Skip to content

Commit

Permalink
Merge pull request #1215 from markt-asf/fix-el-lambda-coercion
Browse files Browse the repository at this point in the history
EL - Fix failing lambda coercion test and other fixes
  • Loading branch information
alwin-joseph authored Jan 11, 2024
2 parents a4098af + 21d8e90 commit e0f4b12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -131,15 +131,6 @@ public static boolean testCompositeELResolver(ELContext elContext,
buf.append("getCommonPropertyType() returns ");
buf.append(commonPropertyType.getName() + NL);

// getFeatureDescriptors()
elContext.setPropertyResolved(false);
Iterator i = compResolver.getFeatureDescriptors(elContext, null);
boolean fdPass = ResolverTest.testFeatureDescriptors(i, compResolver, null,
buf);
if (!fdPass) {
pass = false;
}

return pass;
}

Expand Down Expand Up @@ -243,14 +234,6 @@ public static boolean testELResolver(ELContext elContext, ELResolver resolver,
buf.append("getCommonPropertyType() returns ");
buf.append(commonPropertyType.getName() + "" + NL);

// getFeatureDescriptors()
elContext.setPropertyResolved(false);
Iterator i = resolver.getFeatureDescriptors(elContext, base);
boolean fdPass = ResolverTest.testFeatureDescriptors(i, resolver, base,
buf);
if (!fdPass) {
pass = false;
}
return pass;
}

Expand Down
30 changes: 20 additions & 10 deletions el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021 Oracle and/or its affiliates and others.
* Copyright (c) 2009, 2024 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -1814,28 +1814,38 @@ public void elCoerceLambdaExpressionToFunctionalInterfaceTest() throws Exception
* both compareTo(Object) and compareTo(Long)/compareTo(String) methods will be found as potential matches. The
* method matching rules (see section 1.2.1.2 of the specification) require that overload resolution has a higher
* precedence than coercion resolution so it is always the compareTo(Object) method that will be used for the
* followingtests.
* following tests resulting in a ClassCastException (which is wrapped in an ELException).
*/

// Coercible lambda expression with wrong type
ELProcessor elp3 = new ELProcessor();
elp3.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateLong");
result = elp3.eval("testPredicateLong(x -> x.compareTo('data') == 0)");
pass[3] = ExprEval.compareClass(result, String.class) && ExprEval.compareValue(result, "BLOCK");
try {
result = elp3.eval("testPredicateLong(x -> x.compareTo('data') == 0)");
} catch (ELException e) {
// String 'data' cannot be cast to Long
pass[3] = true;
}

// Coercible lambda expression where filter does not match and parameter needs to be coerced
ELProcessor elp4 = new ELProcessor();
elp4.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateString");
result = elp4.eval("testPredicateString(x -> x.compareTo(1234) == 0)");
pass[4] = ExprEval.compareClass(result, String.class) && ExprEval.compareValue(result, "BLOCK");
try {
result = elp4.eval("testPredicateString(x -> x.compareTo(1234) == 0)");
} catch (ELException e) {
// Long 1234 cannot be cast to String. It is coercible but that should not used here.
pass[4] = true;
}

// Coercible lambda expression with coercible type but coercion rules mean this test fails
ELProcessor elp5 = new ELProcessor();
elp5.defineFunction("", "", "com.sun.ts.tests.el.spec.coercion.ELClientIT", "testPredicateLong");
result = elp5.eval("testPredicateLong(x -> x.compareTo('1234') == 0)");
pass[5] = ExprEval.compareClass(result, String.class) && ExprEval.compareValue(result, "BLOCK");


try {
result = elp5.eval("testPredicateLong(x -> x.compareTo('1234') == 0)");
} catch (ELException e) {
// String '1234' cannot be cast to String. It is coercible but that should not used here.
pass[5] = true;
}
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Testing coercion of lambda expressions to functional interfaces " +
"threw an Exception!" + TestUtil.NEW_LINE + "Received: " + e.toString() + TestUtil.NEW_LINE);
Expand Down

0 comments on commit e0f4b12

Please sign in to comment.