commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1214986 - in /commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src: main/java/org/apache/commons/jexl2/internal/MethodExecutor.java test/java/org/apache/commons/jexl2/IssuesTest.java
Date Thu, 15 Dec 2011 23:10:21 GMT
Author: henrib
Date: Thu Dec 15 23:10:21 2011
New Revision: 1214986

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

Modified:
    commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
    commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/test/java/org/apache/commons/jexl2/IssuesTest.java

Modified: commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java?rev=1214986&r1=1214985&r2=1214986&view=diff
==============================================================================
--- commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
(original)
+++ commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/main/java/org/apache/commons/jexl2/internal/MethodExecutor.java
Thu Dec 15 23:10:21 2011
@@ -27,6 +27,7 @@ import org.apache.commons.jexl2.internal
 public final class MethodExecutor extends AbstractExecutor.Method {
     /** Whether this method handles varargs. */
     private final boolean isVarArgs;
+
     /**
      * Creates a new instance.
      * @param is the introspector used to discover the method
@@ -49,7 +50,7 @@ public final class MethodExecutor extend
      */
     @Override
     public Object execute(Object o, Object[] args)
-        throws IllegalAccessException, InvocationTargetException  {
+            throws IllegalAccessException, InvocationTargetException {
         if (isVarArgs) {
             Class<?>[] formal = method.getParameterTypes();
             int index = formal.length - 1;
@@ -83,7 +84,6 @@ public final class MethodExecutor extend
         return TRY_FAILED;
     }
 
-
     /**
      * Discovers a method for a {@link MethodExecutor}.
      * <p>
@@ -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 {
@@ -158,7 +162,7 @@ public final class MethodExecutor extend
         return actual;
     }
 
-   /**
+    /**
      * Determines if a method can accept a variable number of arguments.
      * @param m a the method to check
      * @return true if method is vararg, false otherwise
@@ -175,5 +179,3 @@ public final class MethodExecutor extend
         }
     }
 }
-
-

Modified: commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1214986&r1=1214985&r2=1214986&view=diff
==============================================================================
--- commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/test/java/org/apache/commons/jexl2/IssuesTest.java
(original)
+++ commons/proper/jexl/tags/COMMONS_JEXL_2_1-RC3/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Thu Dec 15 23:10:21 2011
@@ -827,4 +827,27 @@ public class IssuesTest extends JexlTest
         result = get1.execute(null, quux);
         assertEquals(24, result);
     }
+    
+    public static class Jeff {
+        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 void test124() throws Exception {
+        JexlEngine jexl = new JexlEngine();
+        Script script = jexl.createScript("jeff.concat(['1', '2', '3'])", "jeff");
+        Object res = script.execute(null, new Jeff());
+        assertEquals("1, 2, 3", res);
+    }
 }



Mime
View raw message