-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Deprecate AnnotationFilter.NONE (since MergedAnnotations always filters java.lang.* annotations) #24932
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
Thanks for reporting the issue and for providing the test case. I have confirmed that the test fails as claimed against I have also confirmed that the cause of this behavior is that In other words, the application of |
Tentatively slated for 5.2.6 for team discussion |
We've decided to deprecate As a consequence, I'm repurposing this ticket for the deprecation step and related documentation. |
@jhoeller @sbrannen Thanks for clarifying the situation of the reported problem. You're proposing to use the I'd appreciate a little hint on this from your side. Maybe I'm just missing a method? For the moment, I'm using code like this to "workaround" this: if (AnnotationFilter.PLAIN.matches(annotationType)) {
// PLAIN annotations are ignored by merged annotations API, see
// https://github.com/spring-projects/spring-framework/issues/24932
return Arrays.stream(annotatedElement.getAnnotationsByType(annotationType));
} else {
return mergedAnnotations.stream(annotationType).map(MergedAnnotation::synthesize);
} |
Uh oh!
There was an error while loading. Please reload this page.
The following test case
fails although I've specified
AnnotationFilter.NONE
instead of the defaultAnnotationFilter.PLAIN
filter option. I'd expect the annotation to be found (and thus the I expect the list to contain one element instead of being empty).I suspect this is a bug since as a user of the MergedAnnotations API I expect that the
AnnotationFilter.NONE
returns all possible annotations, even if they're part ofjava.lang
package.I think I tracked the problem down to the following method
org.springframework.core.annotation.AnnotationsScanner#isIgnorable
:which is used when getting the list of annotations from the annotated element in
org.springframework.core.annotation.AnnotationsScanner#getDeclaredAnnotations(java.lang.reflect.AnnotatedElement, boolean)
. However, I'm no expert for this part of the framework and I might be that I'm mistaken if that's the origin of the bug.I don't know how to propose a fix for this and why this
isIgnorable
method is used, but I hope you agreed that this is a bug or at least unexpected behavior for using the filter optionNONE
.Also note that this bug is usually hidden by a shortcut in for example
org.springframework.core.annotation.AnnotationUtils#findAnnotation
:So either the comment is not correct that this is just a shortcut but actually also finding annotations matching
PLAIN
, or the MergedAnnotations API has a bug, as explained above.Background: I'm working on a Spring-based library and would like to find a bunch of annotations, some of them mergable, but some not. I wouldn't like to use different search utilities and always use the MergedAnnotations API, no matter what kind of annotation I'm looking for within my library.
Thanks a lot for investigating!
The text was updated successfully, but these errors were encountered: