Browse Source

fixed autoboxing bug

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1205 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Keith Donald 17 years ago
parent
commit
e8dc69f11c
  1. 11
      org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java
  2. 8
      org.springframework.expression/src/test/java/org/springframework/expression/spel/HelperTests.java

11
org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericTypeConverter.java

@ -38,9 +38,8 @@ import org.springframework.util.Assert; @@ -38,9 +38,8 @@ import org.springframework.util.Assert;
/**
* Base implementation of a conversion service. Initially empty, e.g. no converters are registered by default.
*
* TODO - custom converters
* TODO - object to collection/map converters
* TODO - allow registration of converters to apply on presence of annotation values on setter or field e.g. String-to-@Mask String to apply a mask
* TODO - allow registration of converters to apply on presence of annotation values on setter or field
*
* @author Keith Donald
*/
@ -141,9 +140,6 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { @@ -141,9 +140,6 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
if (source == null) {
return null;
}
if (source.getClass().isAssignableFrom(targetType.getType())) {
return (T) source;
}
ConversionExecutor executor = getConversionExecutor(source.getClass(), targetType);
if (executor != null) {
return (T) executor.execute(source);
@ -196,7 +192,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry { @@ -196,7 +192,10 @@ public class GenericTypeConverter implements TypeConverter, ConverterRegistry {
return null;
}
}
Converter converter = findRegisteredConverter(sourceClass, targetType.getType());
if (sourceType.isAssignableTo(targetType)) {
return NoOpConversionExecutor.INSTANCE;
}
Converter converter = findRegisteredConverter(sourceType.getType(), targetType.getType());
if (converter != null) {
return new StaticConversionExecutor(sourceType, targetType, converter);
} else {

8
org.springframework.expression/src/test/java/org/springframework/expression/spel/HelperTests.java

@ -113,16 +113,16 @@ public class HelperTests extends ExpressionTestCase { @@ -113,16 +113,16 @@ public class HelperTests extends ExpressionTestCase {
StandardTypeConverter typeConverter = new StandardTypeConverter();
// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
//checkMatch(new Class[]{String.class,Integer.TYPE},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,1);
checkMatch(new Class[]{String.class,Integer.TYPE},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,1);
// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
//checkMatch(new Class[]{Integer.TYPE,String.class},new Class[]{Integer.class, String.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0);
checkMatch(new Class[]{Integer.TYPE,String.class},new Class[]{Integer.class, String.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0);
// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
//checkMatch(new Class[]{Integer.TYPE,Sub.class},new Class[]{Integer.class, Super.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0);
checkMatch(new Class[]{Integer.TYPE,Sub.class},new Class[]{Integer.class, Super.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0);
// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
//checkMatch(new Class[]{Integer.TYPE,Sub.class,Boolean.TYPE},new Class[]{Integer.class, Super.class,Boolean.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0,2);
checkMatch(new Class[]{Integer.TYPE,Sub.class,Boolean.TYPE},new Class[]{Integer.class, Super.class,Boolean.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0,2);
}
public void testReflectionHelperCompareArguments_NotAMatch() {

Loading…
Cancel
Save