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 2023/01/23 19:54:52 UTC

[tomcat] branch main updated: Fix BZ 66419 - handle varargs call with single argument

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 8c6f2972be Fix BZ 66419 - handle varargs call with single argument
8c6f2972be is described below

commit 8c6f2972beb5f4c7809dddf5633b696e3f069b4a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 23 19:54:46 2023 +0000

    Fix BZ 66419 - handle varargs call with single argument
---
 java/org/apache/el/parser/AstFunction.java     | 11 ++++++++++-
 test/org/apache/el/parser/TestAstFunction.java | 22 ++++++++++++++++++++++
 webapps/docs/changelog.xml                     |  8 ++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/el/parser/AstFunction.java b/java/org/apache/el/parser/AstFunction.java
index 4d67cfec36..bac8db1be9 100644
--- a/java/org/apache/el/parser/AstFunction.java
+++ b/java/org/apache/el/parser/AstFunction.java
@@ -163,7 +163,7 @@ public final class AstFunction extends SimpleNode {
                     if (m.isVarArgs() && i == methodParameterCount - 1) {
                         if (inputParameterCount < methodParameterCount) {
                             params[i] = new Object[] { null };
-                        } else if (inputParameterCount == methodParameterCount && paramTypes[i].isArray()) {
+                        } else if (inputParameterCount == methodParameterCount && isArray(parameters.jjtGetChild(i).getValue(ctx))) {
                             params[i] = parameters.jjtGetChild(i).getValue(ctx);
                         } else {
                             Object[] varargs = new Object[inputParameterCount - methodParameterCount + 1];
@@ -200,6 +200,15 @@ public final class AstFunction extends SimpleNode {
         return result;
     }
 
+
+    private boolean isArray(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        return obj.getClass().isArray();
+    }
+
+
     public void setLocalName(String localName) {
         this.localName = localName;
     }
diff --git a/test/org/apache/el/parser/TestAstFunction.java b/test/org/apache/el/parser/TestAstFunction.java
index 5697f020e3..4b3a6572bd 100644
--- a/test/org/apache/el/parser/TestAstFunction.java
+++ b/test/org/apache/el/parser/TestAstFunction.java
@@ -16,7 +16,10 @@
  */
 package org.apache.el.parser;
 
+import jakarta.el.ELContext;
 import jakarta.el.ELProcessor;
+import jakarta.el.ExpressionFactory;
+import jakarta.el.StandardELContext;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -37,4 +40,23 @@ public class TestAstFunction {
         Object result = processor.getValue("valueOf(1000)", Integer.class);
         Assert.assertEquals(Integer.valueOf(1000), result);
     }
+
+    @Test
+    public void testVarargMethod() throws NoSuchMethodException, SecurityException {
+        ExpressionFactory factory = ExpressionFactory.newInstance();
+        ELContext context = new StandardELContext(factory);
+        context.getFunctionMapper().mapFunction("fn", "format",
+                String.class.getMethod("format", String.class, Object[].class));
+
+        //Object result = factory.createValueExpression(context, "${fn:format('%s-%s','one','two')}", String.class)
+        //        .getValue(context);
+        //Assert.assertEquals("one-two", result);
+
+        Object result = factory.createValueExpression(context, "${fn:format('%s-%s','one,two'.split(','))}", String.class)
+                .getValue(context);
+        Assert.assertEquals("one-two", result);
+
+        result = factory.createValueExpression(context, "${fn:format('%s','one')}", String.class).getValue(context);
+        Assert.assertEquals("one", result);
+    }
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index fec228945e..9fba57e37f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -148,6 +148,14 @@
       </add>
     </changelog>
   </subsection>
+  <subsection name="Jasper">
+    <changelog>
+      <fix>
+        <bug>66419</bug>: Fix calls from expression language to a method that
+        accepts varargs when only one argument was passed. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <update>


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