diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java index 0fcc7febfc..8a5272d62c 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java @@ -42,6 +42,7 @@ import org.springframework.core.CollectionFactory; import org.springframework.core.GenericCollectionTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionException; +import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -417,12 +418,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra try { return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam); } - catch (IllegalArgumentException ex) { + catch (ConverterNotFoundException ex) { + throw new ConversionNotSupportedException(value, requiredType, ex); + } + catch (ConversionException ex) { throw new TypeMismatchException(value, requiredType, ex); } catch (IllegalStateException ex) { throw new ConversionNotSupportedException(value, requiredType, ex); } + catch (IllegalArgumentException ex) { + throw new TypeMismatchException(value, requiredType, ex); + } } /** @@ -1105,12 +1112,12 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra throw new MethodInvocationException(propertyChangeEvent, ex.getTargetException()); } } - catch (ConversionException ex) { + catch (ConverterNotFoundException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); - throw new TypeMismatchException(pce, pd.getPropertyType(), ex); + throw new ConversionNotSupportedException(pce, pd.getPropertyType(), ex); } - catch (IllegalArgumentException ex) { + catch (ConversionException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new TypeMismatchException(pce, pd.getPropertyType(), ex); @@ -1120,6 +1127,11 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); throw new ConversionNotSupportedException(pce, pd.getPropertyType(), ex); } + catch (IllegalArgumentException ex) { + PropertyChangeEvent pce = + new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); + throw new TypeMismatchException(pce, pd.getPropertyType(), ex); + } catch (IllegalAccessException ex) { PropertyChangeEvent pce = new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue()); diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java b/org.springframework.beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java index fab3fc3825..afd6a0fc09 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java @@ -19,26 +19,32 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; /** - * Exception thrown when no suitable editor can be found to set a bean property. + * Exception thrown when no suitable editor or converter can be found for a bean property. * * @author Arjen Poutsma + * @author Juergen Hoeller * @since 3.0 */ public class ConversionNotSupportedException extends TypeMismatchException { - public ConversionNotSupportedException(PropertyChangeEvent propertyChangeEvent, Class requiredType) { - super(propertyChangeEvent, requiredType); - } - + /** + * Create a new ConversionNotSupportedException. + * @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem + * @param requiredType the required target type (or null if not known) + * @param cause the root cause (may be null) + */ public ConversionNotSupportedException(PropertyChangeEvent propertyChangeEvent, Class requiredType, Throwable cause) { super(propertyChangeEvent, requiredType, cause); } - public ConversionNotSupportedException(Object value, Class requiredType) { - super(value, requiredType); - } - + /** + * Create a new ConversionNotSupportedException. + * @param value the offending value that couldn't be converted (may be null) + * @param requiredType the required target type (or null if not known) + * @param cause the root cause (may be null) + */ public ConversionNotSupportedException(Object value, Class requiredType, Throwable cause) { super(value, requiredType, cause); } + } diff --git a/org.springframework.context/src/test/java/org/springframework/context/conversionservice/TestClient.java b/org.springframework.context/src/test/java/org/springframework/context/conversionservice/TestClient.java index c8e460707b..202ee24e77 100644 --- a/org.springframework.context/src/test/java/org/springframework/context/conversionservice/TestClient.java +++ b/org.springframework.context/src/test/java/org/springframework/context/conversionservice/TestClient.java @@ -32,6 +32,8 @@ public class TestClient { private boolean bool; + private List stringList; + private Resource[] resourceArray; private List resourceList; @@ -56,6 +58,14 @@ public class TestClient { this.bool = bool; } + public List getStringList() { + return stringList; + } + + public void setStringList(List stringList) { + this.stringList = stringList; + } + public Resource[] getResourceArray() { return resourceArray; } diff --git a/org.springframework.context/src/test/resources/org/springframework/context/conversionservice/conversionService.xml b/org.springframework.context/src/test/resources/org/springframework/context/conversionservice/conversionService.xml index 63223400b5..f4c856877f 100644 --- a/org.springframework.context/src/test/resources/org/springframework/context/conversionservice/conversionService.xml +++ b/org.springframework.context/src/test/resources/org/springframework/context/conversionservice/conversionService.xml @@ -13,6 +13,14 @@ + + + #{'test-' + strValue + '-end'} + #{'test-' + strValue} + #{'test-' + numValue+ '-end'} + #{'test-' + numValue} + + classpath:test.xml @@ -36,7 +44,15 @@ - + + + + + + + + +