Skip to content

Commit 580dc8e

Browse files
committed
typed map and collection conversion routines now eagerly reject non-assignable required types and avoid spurious InvocationException stack traces in debug log (SPR-7058)
1 parent 66d2c66 commit 580dc8e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ protected Collection convertToTypedCollection(
520520
Collection original, String propertyName, Class requiredType, TypeDescriptor typeDescriptor) {
521521

522522
boolean originalAllowed = requiredType.isInstance(original);
523+
if (!originalAllowed && !Collection.class.isAssignableFrom(requiredType)) {
524+
return original;
525+
}
526+
523527
MethodParameter methodParam = typeDescriptor.getMethodParameter();
524528
Class elementType = null;
525529
if (methodParam != null) {
@@ -594,8 +598,14 @@ protected Collection convertToTypedCollection(
594598
}
595599

596600
@SuppressWarnings("unchecked")
597-
protected Map convertToTypedMap(Map original, String propertyName, Class requiredType, TypeDescriptor typeDescriptor) {
601+
protected Map convertToTypedMap(
602+
Map original, String propertyName, Class requiredType, TypeDescriptor typeDescriptor) {
603+
598604
boolean originalAllowed = requiredType.isInstance(original);
605+
if (!originalAllowed && !Map.class.isAssignableFrom(requiredType)) {
606+
return original;
607+
}
608+
599609
Class keyType = null;
600610
Class valueType = null;
601611
MethodParameter methodParam = typeDescriptor.getMethodParameter();

0 commit comments

Comments
 (0)