You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/09/17 20:34:19 UTC

[tomcat] branch 10.0.x updated: Fix MethodExpression.getMethodInfo() when parameters are provided

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
     new 99f38cc  Fix MethodExpression.getMethodInfo() when parameters are provided
99f38cc is described below

commit 99f38cc603b873e406d4d33cdc92983046556ffd
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 7797e81..53ce2d6 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 a1b5ade..2178ce7 100644
--- a/test/org/apache/el/TestMethodExpressionImpl.java
+++ b/test/org/apache/el/TestMethodExpressionImpl.java
@@ -22,6 +22,7 @@ import jakarta.el.ELContext;
 import jakarta.el.ELProcessor;
 import jakarta.el.ExpressionFactory;
 import jakarta.el.MethodExpression;
+import jakarta.el.MethodInfo;
 import jakarta.el.MethodNotFoundException;
 import jakarta.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 068deb4..b6c4cec 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 10.0.11 (markt)" rtext="release in progress">
   <subsection name="Catalina">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org