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 20:27:02 UTC

[tomcat] branch 9.0.x updated (929153dacd -> ddcb285fb7)

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

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


    from 929153dacd Fix typo in changelog.
     new 3c6dbcdce4 Re-format. No functional change.
     new b6f1bef800 Fix BZ 66419 - handle varargs call with single argument
     new ddcb285fb7 Skip additional JARs (mostly ones used in Tomcat tests)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 conf/catalina.properties                       | 10 +++-
 java/org/apache/el/parser/AstFunction.java     | 64 ++++++++++++--------------
 test/org/apache/el/parser/TestAstFunction.java | 25 +++++++++-
 webapps/docs/changelog.xml                     |  8 ++++
 4 files changed, 68 insertions(+), 39 deletions(-)


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


[tomcat] 01/03: Re-format. No functional change.

Posted by ma...@apache.org.
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

commit 3c6dbcdce486105b3f0fa39129b78f4c3a6645d2
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jan 20 20:13:18 2023 +0000

    Re-format. No functional change.
---
 java/org/apache/el/parser/AstFunction.java     | 55 ++++++++++----------------
 test/org/apache/el/parser/TestAstFunction.java |  3 +-
 2 files changed, 21 insertions(+), 37 deletions(-)

diff --git a/java/org/apache/el/parser/AstFunction.java b/java/org/apache/el/parser/AstFunction.java
index e054349220..833468e9d5 100644
--- a/java/org/apache/el/parser/AstFunction.java
+++ b/java/org/apache/el/parser/AstFunction.java
@@ -61,8 +61,7 @@ public final class AstFunction extends SimpleNode {
     }
 
     @Override
-    public Class<?> getType(EvaluationContext ctx)
-            throws ELException {
+    public Class<?> getType(EvaluationContext ctx) throws ELException {
 
         FunctionMapper fnMapper = ctx.getFunctionMapper();
 
@@ -72,15 +71,13 @@ public final class AstFunction extends SimpleNode {
         }
         Method m = fnMapper.resolveFunction(this.prefix, this.localName);
         if (m == null) {
-            throw new ELException(MessageFactory.get("error.fnMapper.method",
-                    this.getOutputName()));
+            throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName()));
         }
         return m.getReturnType();
     }
 
     @Override
-    public Object getValue(EvaluationContext ctx)
-            throws ELException {
+    public Object getValue(EvaluationContext ctx) throws ELException {
 
         FunctionMapper fnMapper = ctx.getFunctionMapper();
 
@@ -92,8 +89,8 @@ public final class AstFunction extends SimpleNode {
 
         if (m == null && this.prefix.length() == 0) {
             // TODO: Do we need to think about precedence of the various ways
-            //       a lambda expression may be obtained from something that
-            //       the parser thinks is a function?
+            // a lambda expression may be obtained from something that
+            // the parser thinks is a function?
             Object obj = null;
             if (ctx.isLambdaArgument(this.localName)) {
                 obj = ctx.getLambdaArgument(this.localName);
@@ -114,18 +111,15 @@ public final class AstFunction extends SimpleNode {
             if (obj instanceof LambdaExpression) {
                 // Build arguments
                 int i = 0;
-                while (obj instanceof LambdaExpression &&
-                        i < jjtGetNumChildren()) {
+                while (obj instanceof LambdaExpression && i < jjtGetNumChildren()) {
                     Node args = jjtGetChild(i);
-                    obj = ((LambdaExpression) obj).invoke(
-                            ((AstMethodParameters) args).getParameters(ctx));
+                    obj = ((LambdaExpression) obj).invoke(((AstMethodParameters) args).getParameters(ctx));
                     i++;
                 }
                 if (i < jjtGetNumChildren()) {
                     // Haven't consumed all the sets of parameters therefore
                     // there were too many sets of parameters
-                    throw new ELException(MessageFactory.get(
-                            "error.lambda.tooManyMethodParameterSets"));
+                    throw new ELException(MessageFactory.get("error.lambda.tooManyMethodParameterSets"));
                 }
                 return obj;
             }
@@ -138,22 +132,19 @@ public final class AstFunction extends SimpleNode {
             }
             obj = ctx.getImportHandler().resolveStatic(this.localName);
             if (obj != null) {
-                return ctx.getELResolver().invoke(ctx, new ELClass((Class<?>) obj), this.localName,
-                        null, ((AstMethodParameters) this.children[0]).getParameters(ctx));
+                return ctx.getELResolver().invoke(ctx, new ELClass((Class<?>) obj), this.localName, null,
+                        ((AstMethodParameters) this.children[0]).getParameters(ctx));
             }
         }
 
         if (m == null) {
-            throw new ELException(MessageFactory.get("error.fnMapper.method",
-                    this.getOutputName()));
+            throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName()));
         }
 
         // Not a lambda expression so must be a function. Check there is just a
         // single set of method parameters
         if (this.jjtGetNumChildren() != 1) {
-            throw new ELException(MessageFactory.get(
-                    "error.function.tooManyMethodParameterSets",
-                    getOutputName()));
+            throw new ELException(MessageFactory.get("error.function.tooManyMethodParameterSets", getOutputName()));
         }
 
         Node parameters = jjtGetChild(0);
@@ -171,16 +162,14 @@ 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 && paramTypes[i].isArray()) {
                             params[i] = parameters.jjtGetChild(i).getValue(ctx);
                         } else {
-                            Object[] varargs =
-                                    new Object[inputParameterCount - methodParameterCount + 1];
+                            Object[] varargs = new Object[inputParameterCount - methodParameterCount + 1];
                             Class<?> target = paramTypes[i].getComponentType();
                             for (int j = i; j < inputParameterCount; j++) {
-                                varargs[j-i] = parameters.jjtGetChild(j).getValue(ctx);
-                                varargs[j-i] = coerceToType(ctx, varargs[j-i], target);
+                                varargs[j - i] = parameters.jjtGetChild(j).getValue(ctx);
+                                varargs[j - i] = coerceToType(ctx, varargs[j - i], target);
                             }
                             params[i] = varargs;
                         }
@@ -190,15 +179,13 @@ public final class AstFunction extends SimpleNode {
                     params[i] = coerceToType(ctx, params[i], paramTypes[i]);
                 }
             } catch (ELException ele) {
-                throw new ELException(MessageFactory.get("error.function", this
-                        .getOutputName()), ele);
+                throw new ELException(MessageFactory.get("error.function", this.getOutputName()), ele);
             }
         }
         try {
             result = m.invoke(null, params);
         } catch (IllegalAccessException iae) {
-            throw new ELException(MessageFactory.get("error.function", this
-                    .getOutputName()), iae);
+            throw new ELException(MessageFactory.get("error.function", this.getOutputName()), iae);
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getCause();
             if (cause instanceof ThreadDeath) {
@@ -207,8 +194,7 @@ public final class AstFunction extends SimpleNode {
             if (cause instanceof VirtualMachineError) {
                 throw (VirtualMachineError) cause;
             }
-            throw new ELException(MessageFactory.get("error.function", this
-                    .getOutputName()), cause);
+            throw new ELException(MessageFactory.get("error.function", this.getOutputName()), cause);
         }
         return result;
     }
@@ -223,8 +209,7 @@ public final class AstFunction extends SimpleNode {
 
 
     @Override
-    public String toString()
-    {
+    public String toString() {
         return ELParserTreeConstants.jjtNodeName[id] + "[" + this.getOutputName() + "]";
     }
 }
diff --git a/test/org/apache/el/parser/TestAstFunction.java b/test/org/apache/el/parser/TestAstFunction.java
index 25e7e7fbc3..70a2a22f61 100644
--- a/test/org/apache/el/parser/TestAstFunction.java
+++ b/test/org/apache/el/parser/TestAstFunction.java
@@ -33,8 +33,7 @@ public class TestAstFunction {
     @Test
     public void testImport02() {
         ELProcessor processor = new ELProcessor();
-        processor.getELManager().getELContext().getImportHandler()
-                .importStatic("java.lang.Integer.valueOf");
+        processor.getELManager().getELContext().getImportHandler().importStatic("java.lang.Integer.valueOf");
         Object result = processor.getValue("valueOf(1000)", Integer.class);
         Assert.assertEquals(Integer.valueOf(1000), result);
     }


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


[tomcat] 03/03: Skip additional JARs (mostly ones used in Tomcat tests)

Posted by ma...@apache.org.
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

commit ddcb285fb7ad0f6e2bc03511208b136cb5950438
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 23 17:07:37 2023 +0000

    Skip additional JARs (mostly ones used in Tomcat tests)
    
    This speeds up test runs
---
 conf/catalina.properties | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/conf/catalina.properties b/conf/catalina.properties
index 779f761ca1..38ce4c1063 100644
--- a/conf/catalina.properties
+++ b/conf/catalina.properties
@@ -108,10 +108,12 @@ shared.loader=
 tomcat.util.scan.StandardJarScanFilter.jarsToSkip=\
 annotations-api.jar,\
 ant-junit*.jar,\
-ant-launcher.jar,\
-ant.jar,\
+ant-launcher*.jar,\
+ant*.jar,\
 asm-*.jar,\
 aspectj*.jar,\
+bcel*.jar,\
+biz.aQute.bnd*.jar,\
 bootstrap.jar,\
 catalina-ant.jar,\
 catalina-ha.jar,\
@@ -124,6 +126,7 @@ cobertura-*.jar,\
 commons-beanutils*.jar,\
 commons-codec*.jar,\
 commons-collections*.jar,\
+commons-compress*.jar,\
 commons-daemon.jar,\
 commons-dbcp*.jar,\
 commons-digester*.jar,\
@@ -165,6 +168,8 @@ log4j*.jar,\
 mail*.jar,\
 objenesis-*.jar,\
 oraclepki.jar,\
+org.hamcrest.core_*.jar,\
+org.junit_*.jar,\
 oro-*.jar,\
 servlet-api-*.jar,\
 servlet-api.jar,\
@@ -183,6 +188,7 @@ tomcat-util-scan.jar,\
 tomcat-util.jar,\
 tomcat-websocket.jar,\
 tools.jar,\
+unboundid-ldapsdk-*.jar,\
 websocket-api.jar,\
 wsdl4j*.jar,\
 xercesImpl.jar,\


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


[tomcat] 02/03: Fix BZ 66419 - handle varargs call with single argument

Posted by ma...@apache.org.
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

commit b6f1bef80061e6b851a894f2f1372f98e6484578
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 833468e9d5..1e6eeacc34 100644
--- a/java/org/apache/el/parser/AstFunction.java
+++ b/java/org/apache/el/parser/AstFunction.java
@@ -162,7 +162,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];
@@ -199,6 +199,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 70a2a22f61..138ecade40 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 javax.el.ELContext;
 import javax.el.ELProcessor;
+import javax.el.ExpressionFactory;
+import javax.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 ded49284b6..c8b34cd1e8 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -121,6 +121,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