Skip to content

Commit 667851c

Browse files
committed
Avoid computeIfAbsent for createMappings which calls back into same map
Closes gh-35944
1 parent 96aadc2 commit 667851c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private AnnotationTypeMappings(RepeatableContainers repeatableContainers,
7878

7979
private void addAllMappings(Class<? extends Annotation> annotationType,
8080
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
81+
8182
Deque<AnnotationTypeMapping> queue = new ArrayDeque<>();
8283
addIfPossible(queue, null, annotationType, null, false, visitedAnnotationTypes);
8384
while (!queue.isEmpty()) {
@@ -273,11 +274,19 @@ private static class Cache {
273274
*/
274275
AnnotationTypeMappings get(Class<? extends Annotation> annotationType,
275276
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
276-
return this.mappings.computeIfAbsent(annotationType, key -> createMappings(key, visitedAnnotationTypes));
277+
278+
AnnotationTypeMappings result = this.mappings.get(annotationType);
279+
if (result != null) {
280+
return result;
281+
}
282+
result = createMappings(annotationType, visitedAnnotationTypes);
283+
AnnotationTypeMappings existing = this.mappings.putIfAbsent(annotationType, result);
284+
return (existing != null ? existing : result);
277285
}
278286

279287
private AnnotationTypeMappings createMappings(Class<? extends Annotation> annotationType,
280288
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
289+
281290
return new AnnotationTypeMappings(this.repeatableContainers, this.filter, annotationType,
282291
visitedAnnotationTypes);
283292
}

0 commit comments

Comments
 (0)