[LANG-587] avoid NPE in ClassUtils.toClass(Object[])
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@907102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5d5a31a827
commit
8f675dd3cb
|
@ -890,7 +890,8 @@ public class ClassUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>Converts an array of <code>Object</code> in to an array of <code>Class</code> objects.</p>
|
||||
* <p>Converts an array of <code>Object</code> in to an array of <code>Class</code> objects.
|
||||
* If any of these objects is null, a null element will be inserted into the array.</p>
|
||||
*
|
||||
* <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
|
||||
*
|
||||
|
@ -906,7 +907,7 @@ public class ClassUtils {
|
|||
}
|
||||
Class<?>[] classes = new Class[array.length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
classes[i] = array[i].getClass();
|
||||
classes[i] = array[i] == null ? null : array[i].getClass();
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
|
|
@ -906,6 +906,9 @@ public class ClassUtilsTest extends TestCase {
|
|||
|
||||
assertTrue(Arrays.equals(new Class[] { String.class, Integer.class, Double.class },
|
||||
ClassUtils.toClass(new Object[] { "Test", 1, 99d })));
|
||||
|
||||
assertTrue(Arrays.equals(new Class[] { String.class, null, Double.class },
|
||||
ClassUtils.toClass(new Object[] { "Test", null, 99d })));
|
||||
}
|
||||
|
||||
public void test_getShortCanonicalName_Object() {
|
||||
|
|
Loading…
Reference in New Issue