Skip to content

Commit afc40d7

Browse files
committed
Avoid computeIfAbsent for createMappings which calls back into same map
Closes gh-35944 (cherry picked from commit 667851c)
1 parent 3eb1df0 commit afc40d7

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
@@ -76,6 +76,7 @@ private AnnotationTypeMappings(RepeatableContainers repeatableContainers,
7676

7777
private void addAllMappings(Class<? extends Annotation> annotationType,
7878
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
79+
7980
Deque<AnnotationTypeMapping> queue = new ArrayDeque<>();
8081
addIfPossible(queue, null, annotationType, null, visitedAnnotationTypes);
8182
while (!queue.isEmpty()) {
@@ -270,11 +271,19 @@ private static class Cache {
270271
*/
271272
AnnotationTypeMappings get(Class<? extends Annotation> annotationType,
272273
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
273-
return this.mappings.computeIfAbsent(annotationType, key -> createMappings(key, visitedAnnotationTypes));
274+
275+
AnnotationTypeMappings result = this.mappings.get(annotationType);
276+
if (result != null) {
277+
return result;
278+
}
279+
result = createMappings(annotationType, visitedAnnotationTypes);
280+
AnnotationTypeMappings existing = this.mappings.putIfAbsent(annotationType, result);
281+
return (existing != null ? existing : result);
274282
}
275283

276284
private AnnotationTypeMappings createMappings(Class<? extends Annotation> annotationType,
277285
Set<Class<? extends Annotation>> visitedAnnotationTypes) {
286+
278287
return new AnnotationTypeMappings(this.repeatableContainers, this.filter, annotationType,
279288
visitedAnnotationTypes);
280289
}

0 commit comments

Comments
 (0)