commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r907102 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/ClassUtils.java test/java/org/apache/commons/lang3/ClassUtilsTest.java
Date Fri, 05 Feb 2010 21:31:38 GMT
Author: mbenson
Date: Fri Feb  5 21:31:38 2010
New Revision: 907102

URL: http://svn.apache.org/viewvc?rev=907102&view=rev
Log:
[LANG-587] avoid NPE in ClassUtils.toClass(Object[])

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java?rev=907102&r1=907101&r2=907102&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java Fri Feb
 5 21:31:38 2010
@@ -890,7 +890,8 @@
     }
 
     /**
-     * <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 @@
         }
         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;
     }

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java?rev=907102&r1=907101&r2=907102&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java Fri
Feb  5 21:31:38 2010
@@ -906,6 +906,9 @@
 
         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() {



Mime
View raw message