This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new f3b48f8323 Add some more tests along similar lines to ones I added to the TCK f3b48f8323 is described below commit f3b48f8323d858af1034d1f2c0469d6bb4176d78 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Jan 12 12:17:41 2024 +0000 Add some more tests along similar lines to ones I added to the TCK --- test/org/apache/el/lang/TestELSupport.java | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/org/apache/el/lang/TestELSupport.java b/test/org/apache/el/lang/TestELSupport.java index dcdde1d680..87d4f4e224 100644 --- a/test/org/apache/el/lang/TestELSupport.java +++ b/test/org/apache/el/lang/TestELSupport.java @@ -335,6 +335,44 @@ public class TestELSupport { } + /* + * Note: The following tests use compareTo(). When the target object (Long or String) is examined by reflection + * 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 + * following tests resulting in a ClassCastException (which is wrapped in an ELException). + */ + + @Test(expected = ELException.class) + public void testCoercetoFunctionalInterface07() throws Exception { + final ELProcessor elp = new ELProcessor(); + elp.defineFunction("", "", "org.apache.el.lang.TestELSupport", "testPredicateB"); + // This should trigger an exception as String isn't assignable to Long + Object result = elp.eval("testPredicateB(x -> x.compareTo('data') == 0)"); + Assert.assertEquals("BLOCK", result); + } + + + @Test(expected = ELException.class) + public void testCoercetoFunctionalInterface08() throws Exception { + final ELProcessor elp = new ELProcessor(); + elp.defineFunction("", "", "org.apache.el.lang.TestELSupport", "testPredicateA"); + // This should trigger an exception as Long isn't assignable to String + Object result = elp.eval("testPredicateA(x -> x.compareTo(1234) == 0)"); + Assert.assertEquals("BLOCK", result); + } + + + @Test(expected = ELException.class) + public void testCoercetoFunctionalInterface09() throws Exception { + final ELProcessor elp = new ELProcessor(); + elp.defineFunction("", "", "org.apache.el.lang.TestELSupport", "testPredicateB"); + // This should trigger an exception as String isn't assignable to Long despite this String being coercible + Object result = elp.eval("testPredicateB(x -> x.compareTo('1234') == 0)"); + Assert.assertEquals("BLOCK", result); + } + + public static String testPredicateA(Predicate<String> filter) { String s = "data"; if (filter.test(s)) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org