diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java index 95ac57f86e1..7c9f595b230 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java @@ -78,6 +78,7 @@ final class AnnotationTypeMappings { private void addAllMappings(Class annotationType, Set> visitedAnnotationTypes) { + Deque queue = new ArrayDeque<>(); addIfPossible(queue, null, annotationType, null, false, visitedAnnotationTypes); while (!queue.isEmpty()) { @@ -273,11 +274,19 @@ final class AnnotationTypeMappings { */ AnnotationTypeMappings get(Class annotationType, Set> visitedAnnotationTypes) { - return this.mappings.computeIfAbsent(annotationType, key -> createMappings(key, visitedAnnotationTypes)); + + AnnotationTypeMappings result = this.mappings.get(annotationType); + if (result != null) { + return result; + } + result = createMappings(annotationType, visitedAnnotationTypes); + AnnotationTypeMappings existing = this.mappings.putIfAbsent(annotationType, result); + return (existing != null ? existing : result); } private AnnotationTypeMappings createMappings(Class annotationType, Set> visitedAnnotationTypes) { + return new AnnotationTypeMappings(this.repeatableContainers, this.filter, annotationType, visitedAnnotationTypes); }