Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EL - Fix failing lambda coercion test and other fixes #1215

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading