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:36:01 UTC
[tomcat] branch 8.5.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 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new dfe6cb0 Fix MethodExpression.getMethodInfo() when parameters are provided
dfe6cb0 is described below
commit dfe6cb037fb6b50dc2f2cb5fe79fe2f0e16befad
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 3d55a25..2c863e3 100644
--- a/test/org/apache/el/TestMethodExpressionImpl.java
+++ b/test/org/apache/el/TestMethodExpressionImpl.java
@@ -20,6 +20,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;
@@ -913,4 +914,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 5a1cd81..1bd7248 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -119,6 +119,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 8.5.71 (schultz)" rtext="2021-09-13">
<subsection name="Catalina">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org