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
This commit is contained in:
parent
5b5d6b23d1
commit
66f83099a5
|
@ -273,6 +273,9 @@ limitations under the License.
|
|||
<contributor>
|
||||
<name>Andrew C. Oliver</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Alban Peignier</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Moritz Petersen</name>
|
||||
</contributor>
|
||||
|
|
|
@ -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 {
|
|||
/**
|
||||
* <p>Converts the specified primitive Class object to its corresponding
|
||||
* wrapper Class object.</p>
|
||||
*
|
||||
* <p>NOTE: From v2.2, this method handles <code>Void.TYPE</code>,
|
||||
* returning <code>Void.TYPE</code>.</p>
|
||||
*
|
||||
* @param cls the class to convert, may be null
|
||||
* @return the wrapper class for <code>cls</code> or <code>cls</code> if
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue