Author: henrib
Date: Fri Dec 16 07:13:26 2011
New Revision: 1215052

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

Modified:
    
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
    
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/MethodTest.java

Modified: 
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java?rev=1215052&r1=1215051&r2=1215052&view=diff
==============================================================================
--- 
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
 (original)
+++ 
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
 Fri Dec 16 07:13:26 2011
@@ -131,12 +131,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/branches/2.0/src/test/java/org/apache/commons/jexl2/MethodTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/MethodTest.java?rev=1215052&r1=1215051&r2=1215052&view=diff
==============================================================================
--- 
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/MethodTest.java
 (original)
+++ 
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl2/MethodTest.java
 Fri Dec 16 07:13:26 2011
@@ -66,6 +66,19 @@ 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 {
@@ -118,6 +131,8 @@ 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 {


Reply via email to