From 66f83099a50eef67909e4d371dc72d67590e7670 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 14 Jul 2005 22:08:08 +0000 Subject: [PATCH] Fix ClassUtils.primitiveToWrapper() to handle Void.TYPE bug 34327, from Alban Peignier git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@219117 13f79535-47bb-0310-9956-ffa450edef68 --- project.xml | 3 +++ src/java/org/apache/commons/lang/ClassUtils.java | 5 +++++ src/test/org/apache/commons/lang/ClassUtilsTest.java | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/project.xml b/project.xml index 1f3160863..a161f602f 100644 --- a/project.xml +++ b/project.xml @@ -273,6 +273,9 @@ limitations under the License. Andrew C. Oliver + + Alban Peignier + Moritz Petersen diff --git a/src/java/org/apache/commons/lang/ClassUtils.java b/src/java/org/apache/commons/lang/ClassUtils.java index ea60db553..1e978ea83 100644 --- a/src/java/org/apache/commons/lang/ClassUtils.java +++ b/src/java/org/apache/commons/lang/ClassUtils.java @@ -30,6 +30,7 @@ import java.util.Map; * @author Stephen Colebourne * @author Gary Gregory * @author Norm Deane + * @author Alban Peignier * @since 2.0 * @version $Id$ */ @@ -68,6 +69,7 @@ public class ClassUtils { primitiveWrapperMap.put(Long.TYPE, Long.class); primitiveWrapperMap.put(Double.TYPE, Double.class); primitiveWrapperMap.put(Float.TYPE, Float.class); + primitiveWrapperMap.put(Void.TYPE, Void.TYPE); } /** @@ -442,6 +444,9 @@ public class ClassUtils { /** *

Converts the specified primitive Class object to its corresponding * wrapper Class object.

+ * + *

NOTE: From v2.2, this method handles Void.TYPE, + * returning Void.TYPE.

* * @param cls the class to convert, may be null * @return the wrapper class for cls or cls if diff --git a/src/test/org/apache/commons/lang/ClassUtilsTest.java b/src/test/org/apache/commons/lang/ClassUtilsTest.java index f1f05da6f..31ca69455 100644 --- a/src/test/org/apache/commons/lang/ClassUtilsTest.java +++ b/src/test/org/apache/commons/lang/ClassUtilsTest.java @@ -352,6 +352,8 @@ public class ClassUtilsTest extends TestCase { assertEquals("ClassUtils.class -> ClassUtils.class", org.apache.commons.lang.ClassUtils.class, ClassUtils.primitiveToWrapper(org.apache.commons.lang.ClassUtils.class)); + assertEquals("Void.TYPE -> Void.TYPE", + Void.TYPE, ClassUtils.primitiveToWrapper(Void.TYPE)); // test null assertNull("null -> null", @@ -384,7 +386,7 @@ public class ClassUtilsTest extends TestCase { // test an array of no primitive classes final Class[] noPrimitives = new Class[] { - String.class, ClassUtils.class + String.class, ClassUtils.class, Void.TYPE }; // This used to return the exact same array, but no longer does. assertNotSame("unmodified", noPrimitives, ClassUtils.primitivesToWrappers(noPrimitives));