Skip to content

Commit

Permalink
Filter repeatable annotations in AnnotationTypeMappings
Browse files Browse the repository at this point in the history
Prior to this commit, AnnotationTypeMappings did not filter repeatable
annotations with the supplied annotation filter.

Closes spring-projectsgh-25483
  • Loading branch information
yilianhuaixiao authored and xcl(徐程林) committed Aug 16, 2020
1 parent 03c6258 commit 1dd7e43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -89,7 +89,7 @@ private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, Annot
Annotation[] repeatedAnnotations = this.repeatableContainers.findRepeatedAnnotations(metaAnnotation);
if (repeatedAnnotations != null) {
for (Annotation repeatedAnnotation : repeatedAnnotations) {
if (!isMappable(source, metaAnnotation)) {
if (!isMappable(source, repeatedAnnotation)) {
continue;
}
addIfPossible(queue, source, repeatedAnnotation);
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets;
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet;
import org.springframework.lang.UsesSunMisc;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;

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

@Test
void forAnnotationTypeWhenRepeatableMetaAnnotationFilterd() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithRepeatedMetaAnnotations.class,
annotationType ->
ObjectUtils.nullSafeEquals(annotationType, Repeating.class.getName()));
assertThat(getAll(mappings)).flatExtracting(
AnnotationTypeMapping::getAnnotationType).containsExactly(
WithRepeatedMetaAnnotations.class);
}

@Nullable
private Method getAliasMapping(AnnotationTypeMapping mapping, int attributeIndex) {
int mapped = mapping.getAliasMapping(attributeIndex);
Expand Down

0 comments on commit 1dd7e43

Please sign in to comment.