jakartaee / expression-language

Jakarta Expression Language
https://eclipse.org/ee4j/el
Other
67 stars 49 forks source link

Cannot convert javax.el.LambdaExpression #45

Closed glassfishrobot closed 2 years ago

glassfishrobot commented 6 years ago

(also posted on SO)

This test shows my problem:

public static String testMe(Predicate<String> filter) {
    return "yeah!";
}

@Test
public void testPredicateAsArgument() throws ClassNotFoundException, NoSuchMethodException {
    final ELProcessor elp = new ELProcessor();
    elp.defineFunction("", "", "test.EL3Test", "testMe");
    try {
        Object result = elp.eval("testMe(o->true)"); // IllegalArgumentException
        // ...
    } catch (javax.el.ELException ex) {
        fail(Exceptions.getCauseMessage(ex));
    }
}

It throws: IllegalArgumentException: Cannot convert javax.el.LambdaExpression@511baa65 of type class javax.el.LambdaExpression to interface java.util.function.Predicate

Is this a bug or limitation of EL 3 or do i miss something?

glassfishrobot commented 6 years ago
markt-asf commented 4 years ago

It is a limitation of the current EL specification.

This would be a new feature for consideration in Jakarta EE 10.

markt-asf commented 3 years ago

I've been doing some research on this. A generic solution that coerces a LambdaExpression to any functional interface (providing that the types match) looks possible at this point. My plan is to experiment with an implementation in Tomcat and if that is successful add an additional coercion rule to section 1.23 of the EL spec.