This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 2d05397 Fix MethodExpression.getMethodInfo() when parameters are provided 2d05397 is described below commit 2d05397132e8e803781a0c73c72e8e7d825da1d1 Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Sep 17 21:32:38 2021 +0100 Fix MethodExpression.getMethodInfo() when parameters are provided --- java/org/apache/el/parser/AstValue.java | 16 ++++++++++++---- test/org/apache/el/TestMethodExpressionImpl.java | 14 ++++++++++++++ webapps/docs/changelog.xml | 11 +++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/java/org/apache/el/parser/AstValue.java b/java/org/apache/el/parser/AstValue.java index db67312..4db4a50 100644 --- a/java/org/apache/el/parser/AstValue.java +++ b/java/org/apache/el/parser/AstValue.java @@ -212,10 +212,18 @@ public final class AstValue extends SimpleNode { @SuppressWarnings("rawtypes") Class[] paramTypes) throws ELException { Target t = getTarget(ctx); - Method m = ReflectionUtil.getMethod( - ctx, t.base, t.property, paramTypes, null); - return new MethodInfo(m.getName(), m.getReturnType(), m - .getParameterTypes()); + Class<?>[] types = null; + if (isParametersProvided()) { + if (isParametersProvided()) { + Object[] values = ((AstMethodParameters) this.jjtGetChild( + this.jjtGetNumChildren() - 1)).getParameters(ctx); + types = getTypesFromValues(values); + } else { + types = paramTypes; + } + } + Method m = ReflectionUtil.getMethod(ctx, t.base, t.property, types, null); + return new MethodInfo(m.getName(), m.getReturnType(), m.getParameterTypes()); } @Override diff --git a/test/org/apache/el/TestMethodExpressionImpl.java b/test/org/apache/el/TestMethodExpressionImpl.java index e8c4abf..c2811bf 100644 --- a/test/org/apache/el/TestMethodExpressionImpl.java +++ b/test/org/apache/el/TestMethodExpressionImpl.java @@ -22,6 +22,7 @@ import javax.el.ELContext; import javax.el.ELProcessor; import javax.el.ExpressionFactory; import javax.el.MethodExpression; +import javax.el.MethodInfo; import javax.el.MethodNotFoundException; import javax.el.ValueExpression; @@ -761,4 +762,17 @@ public class TestMethodExpressionImpl { String elResult = (String) elp.eval("bean1.echo(bean2)"); Assert.assertEquals("No varargs: xyz", elResult); } + + + @Test + public void testGetMethodInfo01() throws Exception { + MethodExpression me = factory.createMethodExpression(context, + "#{beanA.setName('New value')}", null, null); + // This is the call that failed + MethodInfo mi = me.getMethodInfo(context); + // The rest is to check it worked correctly + Assert.assertEquals(void.class, mi.getReturnType()); + Assert.assertEquals(1, mi.getParamTypes().length); + Assert.assertEquals(String.class, mi.getParamTypes()[0]); + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index e2f28ac..b13acc0 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -137,6 +137,17 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + Fix the implementation of <code>MethodExpression.getMethodInfo()</code> + so that it returns the expected value rather than failing when the + method expression is defined with the parameter values in the expression + rather than the types being passed explicitly to + <code>ExpressionFactory.createMethodExpression()</code>. (markt) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 9.0.53 (remm)" rtext="2021-09-10"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org