commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1369116 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
Date Fri, 03 Aug 2012 17:43:34 GMT
Author: mbenson
Date: Fri Aug  3 17:43:33 2012
New Revision: 1369116

URL: http://svn.apache.org/viewvc?rev=1369116&view=rev
Log:
[LANG-814] ConstructorUtils.invoke*(*, Object... args) variants cannot handle null values

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java?rev=1369116&r1=1369115&r2=1369116&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
Fri Aug  3 17:43:33 2012
@@ -81,10 +81,7 @@ public class ConstructorUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        Class<?> parameterTypes[] = new Class[args.length];
-        for (int i = 0; i < args.length; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?> parameterTypes[] = ClassUtils.toClass(args);
         return invokeConstructor(cls, args, parameterTypes);
     }
 
@@ -148,11 +145,7 @@ public class ConstructorUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        int arguments = args.length;
-        Class<?> parameterTypes[] = new Class[arguments];
-        for (int i = 0; i < arguments; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?> parameterTypes[] = ClassUtils.toClass(args);
         return invokeExactConstructor(cls, args, parameterTypes);
     }
 

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java?rev=1369116&r1=1369115&r2=1369116&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
Fri Aug  3 17:43:33 2012
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
 
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.commons.lang3.mutable.MutableObject;
 
 /**
  * Unit tests ConstructorUtils
@@ -199,6 +200,11 @@ public class ConstructorUtilsTest extend
                 singletonArray(Double.TYPE), singletonArray(Double.TYPE));
     }
 
+    public void testNullArgument() {
+        expectMatchingAccessibleConstructorParameterTypes(MutableObject.class,
+                singletonArray(null), singletonArray(Object.class));
+    }
+
     private void expectMatchingAccessibleConstructorParameterTypes(Class<?> cls,
             Class<?>[] requestTypes, Class<?>[] actualTypes) {
         Constructor<?> c = ConstructorUtils.getMatchingAccessibleConstructor(cls,



Mime
View raw message