Skip to content

Commit f273fa9

Browse files
committed
Use RepeatableContainers.none() in AnnotationUtils
Update `AnnotationUtils` so that `RepeatableContainers.none()` is used when performing an exhaustive search for merged annotations. These parameters were accidentally removed in commit 210b178 and weren't caught earlier because we were missing a test. Closes gh-22702
1 parent 800cbf2 commit f273fa9

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public static <A extends Annotation> A getAnnotation(Annotation annotation, Clas
197197
return null;
198198
}
199199
// Exhaustive retrieval of merged annotations...
200-
return MergedAnnotations.from(annotation)
200+
return MergedAnnotations.from(null, new Annotation[] {annotation},
201+
RepeatableContainers.none(), AnnotationFilter.PLAIN)
201202
.get(annotationType).withNonMergedAttributes()
202203
.synthesize(AnnotationUtils::isSingleLevelPresent).orElse(null);
203204
}
@@ -492,7 +493,8 @@ public static <A extends Annotation> A findAnnotation(
492493
return annotatedElement.getDeclaredAnnotation(annotationType);
493494
}
494495
// Exhaustive retrieval of merged annotations...
495-
return MergedAnnotations.from(annotatedElement, SearchStrategy.INHERITED_ANNOTATIONS)
496+
return MergedAnnotations.from(annotatedElement, SearchStrategy.INHERITED_ANNOTATIONS,
497+
RepeatableContainers.none(), AnnotationFilter.PLAIN)
496498
.get(annotationType).withNonMergedAttributes()
497499
.synthesize(MergedAnnotation::isPresent).orElse(null);
498500
}
@@ -523,7 +525,8 @@ public static <A extends Annotation> A findAnnotation(Method method, @Nullable C
523525
return method.getDeclaredAnnotation(annotationType);
524526
}
525527
// Exhaustive retrieval of merged annotations...
526-
return MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE)
528+
return MergedAnnotations.from(method, SearchStrategy.EXHAUSTIVE,
529+
RepeatableContainers.none(), AnnotationFilter.PLAIN)
527530
.get(annotationType).withNonMergedAttributes()
528531
.synthesize(MergedAnnotation::isPresent).orElse(null);
529532
}
@@ -561,7 +564,8 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable
561564
return clazz.getDeclaredAnnotation(annotationType);
562565
}
563566
// Exhaustive retrieval of merged annotations...
564-
return MergedAnnotations.from(clazz, SearchStrategy.EXHAUSTIVE)
567+
return MergedAnnotations.from(clazz, SearchStrategy.EXHAUSTIVE,
568+
RepeatableContainers.none(), AnnotationFilter.PLAIN)
565569
.get(annotationType).withNonMergedAttributes()
566570
.synthesize(MergedAnnotation::isPresent).orElse(null);
567571
}

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,13 @@ public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases(
979979
assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
980980
}
981981

982+
@Test // gh-22702
983+
public void findAnnotationWithRepeatablesElements() {
984+
assertNull(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
985+
TestRepeatable.class));
986+
assertNotNull(AnnotationUtils.findAnnotation(TestRepeatablesClass.class,
987+
TestRepeatableContainer.class));
988+
}
982989

983990
@SafeVarargs
984991
static <T> T[] asArray(T... arr) {
@@ -1808,4 +1815,21 @@ static class ComponentScanSingleFilterClass {
18081815
interface ContextConfigMismatch {
18091816
}
18101817

1818+
@Retention(RetentionPolicy.RUNTIME)
1819+
@Repeatable(TestRepeatableContainer.class)
1820+
static @interface TestRepeatable {
1821+
1822+
String value();
1823+
}
1824+
1825+
@Retention(RetentionPolicy.RUNTIME)
1826+
static @interface TestRepeatableContainer {
1827+
1828+
TestRepeatable[] value();
1829+
}
1830+
1831+
@TestRepeatable("a")
1832+
@TestRepeatable("b")
1833+
static class TestRepeatablesClass {
1834+
}
18111835
}

0 commit comments

Comments
 (0)