提交 c69e6a36 编写于 作者: J Juergen Hoeller

Revised IllegalArgumentException handling for Formatter parse calls

Issue: SPR-14661
上级 0c2e8a62
...@@ -572,7 +572,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA ...@@ -572,7 +572,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
throw new ConversionNotSupportedException(pce, requiredType, ex); throw new ConversionNotSupportedException(pce, requiredType, ex);
} }
catch (Throwable ex) { catch (IllegalArgumentException ex) {
PropertyChangeEvent pce = PropertyChangeEvent pce =
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue); new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
throw new TypeMismatchException(pce, requiredType, ex); throw new TypeMismatchException(pce, requiredType, ex);
......
...@@ -73,7 +73,7 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport ...@@ -73,7 +73,7 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
catch (IllegalStateException ex) { catch (IllegalStateException ex) {
throw new ConversionNotSupportedException(value, requiredType, ex); throw new ConversionNotSupportedException(value, requiredType, ex);
} }
catch (Throwable ex) { catch (IllegalArgumentException ex) {
throw new TypeMismatchException(value, requiredType, ex); throw new TypeMismatchException(value, requiredType, ex);
} }
} }
......
...@@ -18,7 +18,6 @@ package org.springframework.format.support; ...@@ -18,7 +18,6 @@ package org.springframework.format.support;
import java.beans.PropertyEditor; import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport; import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.format.Formatter; import org.springframework.format.Formatter;
...@@ -65,7 +64,10 @@ public class FormatterPropertyEditorAdapter extends PropertyEditorSupport { ...@@ -65,7 +64,10 @@ public class FormatterPropertyEditorAdapter extends PropertyEditorSupport {
try { try {
setValue(this.formatter.parse(text, LocaleContextHolder.getLocale())); setValue(this.formatter.parse(text, LocaleContextHolder.getLocale()));
} }
catch (ParseException ex) { catch (IllegalArgumentException ex) {
throw ex;
}
catch (Throwable ex) {
throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex); throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
} }
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package org.springframework.format.support; package org.springframework.format.support;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.text.ParseException;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -193,11 +192,14 @@ public class FormattingConversionService extends GenericConversionService ...@@ -193,11 +192,14 @@ public class FormattingConversionService extends GenericConversionService
try { try {
result = this.parser.parse(text, LocaleContextHolder.getLocale()); result = this.parser.parse(text, LocaleContextHolder.getLocale());
} }
catch (ParseException ex) { catch (IllegalArgumentException ex) {
throw ex;
}
catch (Throwable ex) {
throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex); throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
} }
if (result == null) { if (result == null) {
throw new IllegalStateException("Parsers are not allowed to return null"); throw new IllegalStateException("Parsers are not allowed to return null: " + this.parser);
} }
TypeDescriptor resultType = TypeDescriptor.valueOf(result.getClass()); TypeDescriptor resultType = TypeDescriptor.valueOf(result.getClass());
if (!resultType.isAssignableTo(targetType)) { if (!resultType.isAssignableTo(targetType)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册