You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/12/03 22:29:53 UTC

svn commit: r723083 - in /velocity/engine/trunk/src: java/org/apache/velocity/util/introspection/UberspectImpl.java test/org/apache/velocity/test/VarargMethodsTestCase.java

Author: nbubna
Date: Wed Dec  3 13:29:53 2008
New Revision: 723083

URL: http://svn.apache.org/viewvc?rev=723083&view=rev
Log:
VELOCITY-651 fix first part of vararg reflection bug and add breaking test for second part

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/VarargMethodsTestCase.java

Modified: velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java?rev=723083&r1=723082&r2=723083&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/UberspectImpl.java Wed Dec  3 13:29:53 2008
@@ -431,7 +431,10 @@
             if (actual.length == index)
             {
                 // create an empty array of the expected type
-                actual = new Object[] { Array.newInstance(type, 0) };
+                Object[] newActual = new Object[actual.length + 1];
+                System.arraycopy(actual, 0, newActual, 0, actual.length);
+                newActual[index] = Array.newInstance(type, 0);
+                actual = newActual;
             }
             // if one value is being passed into the vararg
             else if (actual.length == index + 1 && actual[index] != null)

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/VarargMethodsTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/VarargMethodsTestCase.java?rev=723083&r1=723082&r2=723083&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/VarargMethodsTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/VarargMethodsTestCase.java Wed Dec  3 13:29:53 2008
@@ -121,6 +121,17 @@
         assertEvalEquals("int[]", "$nasty.test649($null)");
     }
 
+    public void testArgsBeforeVarargWithNoArgs()
+    {
+        assertEvalEquals("String,String,Object[]", "$nasty.test651('a','b')");
+    }
+
+    public void testVelocity651()
+    {
+        DEBUG = true;
+        assertEvalEquals("String,List", "$nasty.test651('test',['TEST'])");
+    }
+
 
 
     public static class NiceTool
@@ -229,6 +240,16 @@
             return "int[]";
         }
 
+        public String test651(String s, String s2, Object[] args)
+        {
+            return "String,String,Object[]";
+        }
+
+        public String test651(String s, java.util.List l)
+        {
+            return "String,List";
+        }
+
     }
 
 }