diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 85fda048e..3998966a7 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -890,7 +890,8 @@ public class ClassUtils { } /** - *

Converts an array of Object in to an array of Class objects.

+ *

Converts an array of Object in to an array of Class objects. + * If any of these objects is null, a null element will be inserted into the array.

* *

This method returns null for a null input array.

* @@ -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; } diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java index 2ea74e710..010ea9342 100644 --- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java @@ -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() {