properly support void.class in TypeDescriptor and GenericConversionService (SPR-7281)
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user