From 379bc5a8a6acd37930f60d558ccc5273ad30fb0f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 11 Jun 2010 21:40:56 +0000 Subject: [PATCH] properly support void.class in TypeDescriptor and GenericConversionService (SPR-7281) --- .../java/org/springframework/util/ClassUtils.java | 4 ++-- .../support/GenericConversionServiceTests.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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));