diff --git a/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java index afe396daba..d51c46fd86 100644 --- a/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java +++ b/el/src/main/java/com/sun/ts/tests/el/spec/coercion/ELClientIT.java @@ -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 @@ -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);