Browse Source

ClassUtils recognizes "void" as primitive type name as well (SPR-7212)

pull/1234/head
Juergen Hoeller 15 years ago
parent
commit
de326e5e95
  1. 5
      org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java
  2. 4
      org.springframework.core/src/test/java/org/springframework/util/ClassUtilsTests.java

5
org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java

@ -89,7 +89,7 @@ public abstract class ClassUtils { @@ -89,7 +89,7 @@ public abstract class ClassUtils {
* Map with primitive type name as key and corresponding primitive
* type as value, for example: "int" -> "int.class".
*/
private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<String, Class<?>>(16);
private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<String, Class<?>>(32);
/**
* Map with common "java.lang" class name as key and corresponding Class as value.
@ -113,11 +113,12 @@ public abstract class ClassUtils { @@ -113,11 +113,12 @@ public abstract class ClassUtils {
registerCommonClasses(entry.getKey());
}
Set<Class<?>> primitiveTypes = new HashSet<Class<?>>(16);
Set<Class<?>> primitiveTypes = new HashSet<Class<?>>(32);
primitiveTypes.addAll(primitiveWrapperTypeMap.values());
primitiveTypes.addAll(Arrays.asList(
boolean[].class, byte[].class, char[].class, double[].class,
float[].class, int[].class, long[].class, short[].class));
primitiveTypes.add(void.class);
for (Class<?> primitiveType : primitiveTypes) {
primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
}

4
org.springframework.core/src/test/java/org/springframework/util/ClassUtilsTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,7 +28,6 @@ import java.util.List; @@ -28,7 +28,6 @@ import java.util.List;
import junit.framework.TestCase;
import org.junit.Ignore;
import org.springframework.beans.DerivedTestBean;
import org.springframework.beans.IOther;
import org.springframework.beans.ITestBean;
@ -76,6 +75,7 @@ public class ClassUtilsTests extends TestCase { @@ -76,6 +75,7 @@ public class ClassUtilsTests extends TestCase {
assertEquals(long.class, ClassUtils.forName("long"));
assertEquals(float.class, ClassUtils.forName("float"));
assertEquals(double.class, ClassUtils.forName("double"));
assertEquals(void.class, ClassUtils.forName("void"));
}
public void testForNameWithPrimitiveArrays() throws ClassNotFoundException {

Loading…
Cancel
Save