Skip to content

Commit 83a9583

Browse files
yilianhuaixiaosbrannen
authored andcommitted
Filter repeatable annotations in AnnotationTypeMappings
Prior to this commit, AnnotationTypeMappings did not filter repeatable annotations with the supplied annotation filter. Closes gh-25483
1 parent b841e85 commit 83a9583

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, Annot
8989
Annotation[] repeatedAnnotations = this.repeatableContainers.findRepeatedAnnotations(metaAnnotation);
9090
if (repeatedAnnotations != null) {
9191
for (Annotation repeatedAnnotation : repeatedAnnotations) {
92-
if (!isMappable(source, metaAnnotation)) {
92+
if (!isMappable(source, repeatedAnnotation)) {
9393
continue;
9494
}
9595
addIfPossible(queue, source, repeatedAnnotation);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets;
3838
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet;
3939
import org.springframework.lang.UsesSunMisc;
40+
import org.springframework.util.ObjectUtils;
4041
import org.springframework.util.ReflectionUtils;
4142

4243
import static java.util.stream.Collectors.toList;
@@ -476,6 +477,16 @@ private Method[] resolveMirrorSets(AnnotationTypeMapping mapping, Class<?> eleme
476477
return result;
477478
}
478479

480+
@Test
481+
void forAnnotationTypeWhenRepeatableMetaAnnotationFilterd() {
482+
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithRepeatedMetaAnnotations.class,
483+
annotationType ->
484+
ObjectUtils.nullSafeEquals(annotationType, Repeating.class.getName()));
485+
assertThat(getAll(mappings)).flatExtracting(
486+
AnnotationTypeMapping::getAnnotationType).containsExactly(
487+
WithRepeatedMetaAnnotations.class);
488+
}
489+
479490
@Nullable
480491
private Method getAliasMapping(AnnotationTypeMapping mapping, int attributeIndex) {
481492
int mapped = mapping.getAliasMapping(attributeIndex);

0 commit comments

Comments
 (0)