properly support void.class in TypeDescriptor and GenericConversionService (SPR-7281)

This commit is contained in:
Juergen Hoeller
2010-06-11 21:40:56 +00:00
parent cbb90236dc
commit 379bc5a8a6
2 changed files with 14 additions and 2 deletions

View File

@@ -794,7 +794,7 @@ public abstract class ClassUtils {
*/
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isPrimitive() ? primitiveTypeToWrapperMap.get(clazz) : clazz);
return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
}
/**
@@ -802,7 +802,7 @@ public abstract class ClassUtils {
* type, assuming setting by reflection. Considers primitive wrapper
* classes as assignable to the corresponding primitive types.
* @param lhsType the target type
* @param rhsType the value type that should be assigned to the target type
* @param rhsType the value type that should be assigned to the target type
* @return if the target type is assignable from the value type
* @see TypeUtils#isAssignable
*/

View File

@@ -81,6 +81,18 @@ public class GenericConversionServiceTests {
}
}
@Test
public void sourceTypeIsVoid() {
GenericConversionService conversionService = new GenericConversionService();
assertFalse(conversionService.canConvert(void.class, String.class));
}
@Test
public void targetTypeIsVoid() {
GenericConversionService conversionService = new GenericConversionService();
assertFalse(conversionService.canConvert(String.class, void.class));
}
@Test
public void convertNull() {
assertNull(conversionService.convert(null, Integer.class));