Skip to content

Commit 15c1941

Browse files
committed
Harmonize exception handling
This commit applies the same catch block to orderForConsistence(Map) than the one that's used for sets. Closes gh-31419
1 parent aab538d commit 15c1941

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGenerator.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,17 @@ protected CodeBlock generateCollectionCode(ResolvableType elementType, Set<?> se
449449
return CodeBlock.of("new $T($L)", LinkedHashSet.class,
450450
generateCollectionOf(set, List.class, elementType));
451451
}
452+
return super.generateCollectionCode(elementType, orderForCodeConsistency(set));
453+
}
454+
455+
private Set<?> orderForCodeConsistency(Set<?> set) {
452456
try {
453-
set = orderForCodeConsistency(set);
457+
return new TreeSet<Object>(set);
454458
}
455459
catch (ClassCastException ex) {
456460
// If elements are not comparable, just keep the original set
461+
return set;
457462
}
458-
return super.generateCollectionCode(elementType, set);
459-
}
460-
461-
private Set<?> orderForCodeConsistency(Set<?> set) {
462-
return new TreeSet<Object>(set);
463463
}
464464
}
465465

@@ -515,7 +515,13 @@ private <K, V> CodeBlock generateMapCode(ResolvableType type, Map<K, V> map) {
515515
}
516516

517517
private <K, V> Map<K, V> orderForCodeConsistency(Map<K, V> map) {
518-
return new TreeMap<>(map);
518+
try {
519+
return new TreeMap<>(map);
520+
}
521+
catch (ClassCastException ex) {
522+
// If elements are not comparable, just keep the original map
523+
return map;
524+
}
519525
}
520526

521527
private <K, V> CodeBlock generateLinkedHashMapCode(Map<K, V> map,

0 commit comments

Comments
 (0)