This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 50ef9d7e4b Add some more tests along similar lines to ones I added to the TCK 50ef9d7e4b is described below commit 50ef9d7e4b6d4706cf2c7493e7294588fe0b9f09 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