diff --git a/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java index 3ce2b2b94d..2c3a9e67de 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java @@ -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 */ diff --git a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index b9b647ee1a..2a10b12607 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -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));