commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1214991 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java test/java/org/apache/commons/jexl3/MethodTest.java
Date Thu, 15 Dec 2011 23:40:46 GMT
Author: henrib
Date: Thu Dec 15 23:40:45 2011
New Revision: 1214991

URL: http://svn.apache.org/viewvc?rev=1214991&view=rev
Log:
Fix and test for JEXL-124

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java?rev=1214991&r1=1214990&r2=1214991&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
Thu Dec 15 23:40:45 2011
@@ -130,12 +130,16 @@ public final class MethodExecutor extend
         // if no values are being passed into the vararg, size == 0
         if (size == 1) {
             // if one non-null value is being passed into the vararg,
+            // and that arg is not the sole argument and not an array of the expected type,
             // make the last arg an array of the expected type
             if (actual[index] != null) {
-                // create a 1-length array to hold and replace the last argument
-                Object lastActual = Array.newInstance(type, 1);
-                Array.set(lastActual, 0, actual[index]);
-                actual[index] = lastActual;
+                Class<?> aclazz = actual[index].getClass();
+                if (!aclazz.isArray() || !aclazz.getComponentType().equals(type)) {
+                    // create a 1-length array to hold and replace the last argument
+                    Object lastActual = Array.newInstance(type, 1);
+                    Array.set(lastActual, 0, actual[index]);
+                    actual[index] = lastActual;
+                }
             }
             // else, the vararg is null and used as is, considered as T[]
         } else {

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java?rev=1214991&r1=1214990&r2=1214991&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java Thu Dec
15 23:40:45 2011
@@ -70,6 +70,20 @@ public class MethodTest extends JexlTest
             }
             return mixed + ":" + result;
         }
+        
+        public String concat(String... strs) {
+            if (strs.length > 0) {
+                StringBuilder strb = new StringBuilder(strs[0]);
+                for(int s = 1; s < strs.length; ++s) {
+                    strb.append(", ");
+                    strb.append(strs[s]);
+                }
+                return strb.toString();
+            } else {
+                return "";
+            }
+            
+        }
     }
 
     public static class Functor {
@@ -133,6 +147,9 @@ public class MethodTest extends JexlTest
         asserter.assertExpression("test.callInts()", "Varargs:0");
         asserter.assertExpression("test.callInts(1)", "Varargs:1");
         asserter.assertExpression("test.callInts(1,2,3,4,5)", "Varargs:15");
+        asserter.assertExpression("test.concat(['1', '2', '3'])", "1, 2, 3");
+        asserter.assertExpression("test.concat('1', '2', '3')", "1, 2, 3");
+        
     }
 
     public void testCallMixedVarArgMethod() throws Exception {



Mime
View raw message