Skip to content

Commit 379bc5a

Browse files
committed
properly support void.class in TypeDescriptor and GenericConversionService (SPR-7281)
1 parent cbb9023 commit 379bc5a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,15 +794,15 @@ public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
794794
*/
795795
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
796796
Assert.notNull(clazz, "Class must not be null");
797-
return (clazz.isPrimitive() ? primitiveTypeToWrapperMap.get(clazz) : clazz);
797+
return (clazz.isPrimitive() && clazz != void.class? primitiveTypeToWrapperMap.get(clazz) : clazz);
798798
}
799799

800800
/**
801801
* Check if the right-hand side type may be assigned to the left-hand side
802802
* type, assuming setting by reflection. Considers primitive wrapper
803803
* classes as assignable to the corresponding primitive types.
804804
* @param lhsType the target type
805-
* @param rhsType the value type that should be assigned to the target type
805+
* @param rhsType the value type that should be assigned to the target type
806806
* @return if the target type is assignable from the value type
807807
* @see TypeUtils#isAssignable
808808
*/

org.springframework.core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ public Object convert(Object source) {
8181
}
8282
}
8383

84+
@Test
85+
public void sourceTypeIsVoid() {
86+
GenericConversionService conversionService = new GenericConversionService();
87+
assertFalse(conversionService.canConvert(void.class, String.class));
88+
}
89+
90+
@Test
91+
public void targetTypeIsVoid() {
92+
GenericConversionService conversionService = new GenericConversionService();
93+
assertFalse(conversionService.canConvert(String.class, void.class));
94+
}
95+
8496
@Test
8597
public void convertNull() {
8698
assertNull(conversionService.convert(null, Integer.class));

0 commit comments

Comments
 (0)