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

2021-09-17 Thread Mark Thomas

On 17/09/2021 21:33, ma...@apache.org wrote:

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 93dd0c2  Fix MethodExpression.getMethodInfo() when parameters are 
provided
93dd0c2 is described below

commit 93dd0c2e2a15b9e5d37a92b4d435c4f53de3c00d
Author: Mark Thomas 
AuthorDate: Fri Sep 17 21:32:38 2021 +0100

 Fix MethodExpression.getMethodInfo() when parameters are provided


Just for background information, I found this while adding some 
additional tests to the EL TCK for 5.0 to provide some coverage for the 
changes between 4.0 and 5.0.


Mark

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



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

2021-09-17 Thread markt
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 93dd0c2  Fix MethodExpression.getMethodInfo() when parameters are 
provided
93dd0c2 is described below

commit 93dd0c2e2a15b9e5d37a92b4d435c4f53de3c00d
Author: Mark Thomas 
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   |  7 +++
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/el/parser/AstValue.java 
b/java/org/apache/el/parser/AstValue.java
index d926867..5a07ef4 100644
--- a/java/org/apache/el/parser/AstValue.java
+++ b/java/org/apache/el/parser/AstValue.java
@@ -213,10 +213,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 085a39f..53816ba 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 = 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 80b359c..ebc8001 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -160,6 +160,13 @@
 NotFoundELResolver. This aligns Tomcat with recent updates
 to the Jakarta Server Pages specification. (markt)
   
+  
+Fix the implementation of MethodExpression.getMethodInfo()
+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
+ExpressionFactory.createMethodExpression(). (markt) 
+  
 
   
 

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