]
Tobias Liefke commented on WFLY-7763:
-------------------------------------
I have to admin, I don't know if this is the correct place to report that type of
problem.
My clue was, that the problematic class {{javax.el.Util}} can be found in
{{jboss-el-api_3.0_spec-1.0.7.Final.jar}} and that WFLY-3456 reports already a similar
(fixed) problem.
"Unable to find unambiguous method" when overriding a
generic method that has more than one parameter
-----------------------------------------------------------------------------------------------------
Key: WFLY-7763
URL:
https://issues.jboss.org/browse/WFLY-7763
Project: WildFly
Issue Type: Bug
Components: JSF
Affects Versions: 10.1.0.Final
Reporter: Tobias Liefke
Assignee: Farah Juma
I've written a generic typed class, which is extended by a class which binds the type
variable:
{code:java}
public abstract class AppendableController<A extends Appendable> {
public String append(A appendable, Number number) {
// ...
}
}
@Named
public class WriterController extends AppendableController<Writer> {
@Override
public String append(Writer writer, Number number) {
//....
}
public Writer getWriter() {
return new StringWriter();
}
public Writer getNoWriter() {
return null;
}
}
{code}
If I reference the {{append}} method in an JSF expression, I found many cases where this
will result in an _MethodNotFoundException_ with the message:
{code}Unable to find unambiguous method{code}
Examples:
* Case 1: {{writerController.append(writerController.writer, 1)}} -> _Unable to find
unambiguous method: WriterController.append(java.io.StringWriter, java.lang.Long)_
* Case 2: {{writerController.append(writerController.noWriter, 1)}} -> _Unable to find
unambiguous method: class org.example.WriterController.append(null, java.lang.Long)_
The reason is that {{WriterController.class.getMethods()}} returns both methods
{{AppendableController.append(Appendable, Number)}} and {{WriterController.append(Writer,
Number)}}.
I see two problems here:
* The type of the parameter is not derived from the type of the parameter expression.
This will lead to non-deterministic behavior of the expression. Either because there are
optional parameters, which might be null (see case 2), or parameters are sometimes proxied
resp. extensions of the parameter type (see case 1).
* In truth there is nothing unambiguous in this example, because both methods map to the
same method invocation of the overridden method, no matter which I would call. It would be
safe to call either of them.