Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [el-dev] Wrong TCK test for ambiguous methods?

Hi Arjan,

EL method matching includes an extra step compared to normal Java matching as it also uses EL coercion. This does make things more complicated as it introduces quite a few additional edge cases.

In summary the target bean in the test below includes these methods:

public String targetE(Long, Long)
public String targetE(String, String)

By calling with a String and a numeric parameter the test is checking the following ambiguity:

Should the the String parameter be coerced to a number and targetE(Long, Long) called or should the numeric parameter be coerced to a String and targetE(String, String) called?

Since there is no way do disambiguate these options (both have one matching type and one coerced type) the match is ambiguous.

Therefore, I think this test is correct.

Mark


On 12/04/2022 23:29, arjan tijms wrote:
Hi,

I was looking at the following test:

/*

* @testName: methodExpressionMatchingAmbiguousTest

*

* @assertion_ids: EL:SPEC:80

*

* @test_Strategy: Validate that MethodExpression does not match a method when

* the match is ambiguous and that a MethodNotFoundException is thrown

*/

*public* *void* methodExpressionMatchingAmbiguousTest() *throws* Fault {


StringBuffer buf = *new* StringBuffer();

String exprStr = "#{bean.targetE('aaa',1234)}";


*boolean* pass = *true*;


*try* {


ExpressionFactory expFactory = ExpressionFactory.newInstance();

ELContext context = (*new* VarMapperELContext(testProps)).getELContext();

MethodsBean bean = *new* MethodsBean();

ValueExpression ve = expFactory.createValueExpression(bean, MethodsBean.*class*);

context.getVariableMapper().setVariable("bean", ve);


MethodExpression me = expFactory.createMethodExpression(context, exprStr, String.*class*, *null*);

me.getMethodInfo(context);

pass = *false*;

} *catch* (MethodNotFoundException mnfe) {

pass = *true*;

} *catch* (Exception ex) {

pass = *false*;

TestUtil.logErr("Call to getMethodInfo() with ambiguous method expression "

+ "threw the wrong Exception!"+ NL + "Expected: MethodNotFoundException"

+ NL + "Received: " + ex.toString() + NL);


ex.printStackTrace();

}


*if* (!pass)

*throw* *new* Fault(ELTestUtil.FAIL + buf.toString());

*else*

TestUtil.logTrace(buf.toString());

}


The methodsBean has the follows two targetE methods:

*  public* String targetE(Long arg0, Long arg1) {

*return*"Long-Long";

}


*public* String targetE(String arg0, String arg1) {

*return*"String-String";

}


I don't see a (String, [number]) overload, so I think the method is not testing an ambiguous match, but just a method not found.


Those happen to throw the same exception, so it goes undetected here.


Thoughts?


Kind regards,

Arjan




Back to the top