[LANG-814] ConstructorUtils.invoke*(*, Object... args) variants cannot handle null values

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1369116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Jason Benson 2012-08-03 17:43:33 +00:00
parent 49b63810c0
commit c63041d06c
2 changed files with 8 additions and 9 deletions

View File

@ -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);
}

View File

@ -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,