diff --git a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java index 115af71be..5adbfd867 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java @@ -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); } diff --git a/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java index b923e2f17..583c8c073 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/ConstructorUtilsTest.java @@ -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 extends TestCase { 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,