This is an automated email from the ASF dual-hosted git repository. markt-asf pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 980aceba8b5ee2d047629d7024962e4b573a3538 Author: Mark Thomas <[email protected]> AuthorDate: Thu Nov 5 15:58:25 2026 +0000 Review "Accept zero varargs elements in EL method expression calls" Expand test coverage Co-authored by: Claude / Sonnet 5.5 --- test/org/apache/el/TestMethodExpressionImpl.java | 45 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/test/org/apache/el/TestMethodExpressionImpl.java b/test/org/apache/el/TestMethodExpressionImpl.java index 4630a08e34..8e534ecc6d 100644 --- a/test/org/apache/el/TestMethodExpressionImpl.java +++ b/test/org/apache/el/TestMethodExpressionImpl.java @@ -22,6 +22,7 @@ import java.util.function.Function; import jakarta.el.ELBaseTest; import jakarta.el.ELContext; +import jakarta.el.ELException; import jakarta.el.ELManager; import jakarta.el.ELProcessor; import jakarta.el.ExpressionFactory; @@ -497,15 +498,47 @@ public class TestMethodExpressionImpl extends ELBaseTest { } - @Test(expected = IllegalArgumentException.class) + @Test public void testBug60844() { - // Fewer parameter values than the minimum required by a varargs - // method (here, the fixed parameters only). A single value would be - // a valid number of arguments for this method, so the call below - // with no values is the too-few-parameters case. + // Fewer parameter values than the minimum required by a varargs method. The minimum is the number of fixed + // parameters (one here), not the total number of parameters, and that is the minimum that must be reported. MethodExpression me2 = factory.createMethodExpression(context, "${beanC.sayHello}", null, new Class[] { TesterBeanA.class }); - me2.invoke(context, new Object[] { }); + try { + me2.invoke(context, new Object[] {}); + Assert.fail("No exception"); + } catch (IllegalArgumentException iae) { + String msg = iae.getMessage(); + Assert.assertTrue(msg, msg.contains("[sayHello]")); + // Called with [0] parameter(s), expected at least [1] + Assert.assertTrue(msg, msg.contains("[0]")); + Assert.assertTrue(msg, msg.contains("[1]")); + Assert.assertFalse(msg, msg.contains("[2]")); + } + } + + + @Test + public void testBug60844NullParameters() { + MethodExpression me2 = factory.createMethodExpression(context, "${beanC.sayHello}", null, + new Class[] { TesterBeanA.class, TesterBeanB.class }); + try { + me2.invoke(context, null); + Assert.fail("No exception"); + } catch (IllegalArgumentException iae) { + String msg = iae.getMessage(); + Assert.assertTrue(msg, msg.contains("[sayHello]")); + } + } + + + @Test(expected = ELException.class) + public void testBug60844WrongType() { + // The original bug 60844 call: a single value of the wrong type. A single value is a valid number of + // arguments for the varargs method so the failure is now reported when the argument is coerced. + MethodExpression me2 = factory.createMethodExpression(context, "${beanC.sayHello}", null, + new Class[] { TesterBeanA.class, TesterBeanB.class }); + me2.invoke(context, new Object[] { new Object() }); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
