-
Notifications
You must be signed in to change notification settings - Fork 38.5k
AnnotatedElementUtils.getMergedRepeatableAnnotations does not return meta annotations on repeatedly-annotated class #26188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Additional information about this issue: Method overloads of
Once the annotations are determined from the annotated element, further processing of the annotation hierarchy Using private static MergedAnnotations getRepeatableAnnotations(AnnotatedElement element, @Nullable Class<? extends Annotation> containerType, Class<? extends Annotation> annotationType) {
// Instead of: RepeatableContainers.of(annotationType, containerType);
RepeatableContainers repeatableContainers = RepeatableContainers.standardRepeatables();
return MergedAnnotations.from(element, SearchStrategy.INHERITED_ANNOTATIONS, repeatableContainers);
} As an alternative, it's possible to define a separate utility method since the required API components are public. The following is an example using the get semantics. class AnnotatedElementUtilsExt {
static <A extends Annotation> Set<A> getAllMergedRepeatableAnnotations(AnnotatedElement element, Class<A> annotationType) {
assertIsRepeatable(annotationType);
return MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS, RepeatableContainers.standardRepeatables())
.stream(annotationType)
.sorted(highAggregateIndexesFirst())
.collect(MergedAnnotationCollectors.toAnnotationSet());
}
private static <A extends Annotation> void assertIsRepeatable(Class<A> annotationType) {
boolean isRepeatable = annotationType.isAnnotationPresent(Repeatable.class);
Assert.isTrue(isRepeatable, () -> "Annotation type must be a repeatable annotation: " +
"failed to resolve container type for " + annotationType.getName());
}
private static <A extends Annotation> Comparator<MergedAnnotation<A>> highAggregateIndexesFirst() {
return Comparator.<MergedAnnotation<A>> comparingInt(MergedAnnotation::getAggregateIndex).reversed();
}
} |
Hi @mischkes, Sorry for taking such a long time to get to this issue. The good news is that this has been resolved in the interim in conjunction with #20279. Starting with Spring Framework 5.3.24, to get Set<Sql> actual =
AnnotatedElementUtils.getMergedRepeatableAnnotations(DoubleAnnotatedClass.class, Sql.class); I am therefore closing this as a: |
Observed in spring-core 5.2.8.RELEASE via spring-boot 2.3.3.RELEASE
The text was updated successfully, but these errors were encountered: