-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
MergedAnnotations
search does not find container for repeatable annotation
#32731
Comments
@heihei180 I am not sure what could have changed this. The code in text you've shared isn't actionable unfortunately, please share a small sample we can run ourselves that reproduces this behavior. You can attach a zip here or push the code to a GitHub repository. |
@snicoll Thank you for your reply~ I will upload a zip file that contains two folders, demo1 and demo2, both of which are springboot programs, but the versions are different.
Looking forward to your reply! Thank you again. |
Thanks for the sample. I can reproduce, including with the latest release and I don't know if that's intended. Relying on the container annotation for this looks a bit odd to me though. If you use |
Thanks for the demo projects, @heihei180. 👍 I've reduced this to the following test. @Test
void test() {
Extensions extensions = FooService.class.getAnnotation(Extensions.class);
assertThat(extensions).as("@Extensions").isNotNull();
extensions = MergedAnnotations.from(FooService.class, SearchStrategy.TYPE_HIERARCHY)
.get(Extensions.class)
.synthesize(MergedAnnotation::isPresent)
.orElse(null);
assertThat(extensions).as("@Extensions").isNotNull();
}
I consider that a regression, and I'll investigate further. |
The above test actually fails on This appears to be related to #29685, and I assume this bug may have existed since Spring Framework 5.2 when the |
MergedAnnotations
search does not find container for repeatable annotation
This issue turned out be an interesting one... and a combination of a few things.
That's due to a bug in the Specifically, if the The reason is that
That's indeed the case: #29685 allowed the In other words, since Spring Framework 5.3.25, |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
A bug has existed in Spring's MergedAnnotations support since it was introduced in Spring Framework 5.2. Specifically, if the MergedAnnotations API is used to search for annotations with "standard repeatable annotation" support enabled (which is the default), it's possible to search for a repeatable annotation but not for the repeatable annotation's container annotation. The reason is that MergedAnnotationFinder.process(Object, int, Object, Annotation) does not process the container annotation and instead only processes the "contained" annotations, which prevents a container annotation from being included in search results. In #29685, we fixed a bug that prevented the MergedAnnotations support from recognizing an annotation as a container if the container annotation declares attributes other than the required `value` attribute. As a consequence of that bug fix, since Spring Framework 5.3.25, the MergedAnnotations infrastructure considers such an annotation a container, and due to the aforementioned bug the container is no longer processed, which results in a regression in behavior for annotation searches for such a container annotation. This commit addresses the original bug as well as the regression by processing container annotations in addition to the contained repeatable annotations. See gh-29685 Closes gh-32731 (cherry picked from commit 4baad16)
A bug has existed in Spring's MergedAnnotations support since it was introduced in Spring Framework 5.2. Specifically, if the MergedAnnotations API is used to search for annotations with "standard repeatable annotation" support enabled (which is the default), it's possible to search for a repeatable annotation but not for the repeatable annotation's container annotation. The reason is that MergedAnnotationFinder.process(Object, int, Object, Annotation) does not process the container annotation and instead only processes the "contained" annotations, which prevents a container annotation from being included in search results. In #29685, we fixed a bug that prevented the MergedAnnotations support from recognizing an annotation as a container if the container annotation declares attributes other than the required `value` attribute. As a consequence of that bug fix, since Spring Framework 5.3.25, the MergedAnnotations infrastructure considers such an annotation a container, and due to the aforementioned bug the container is no longer processed, which results in a regression in behavior for annotation searches for such a container annotation. This commit addresses the original bug as well as the regression by processing container annotations in addition to the contained repeatable annotations. See gh-29685 Closes gh-32731 (cherry picked from commit 4baad16)
This has been addressed in 4baad16 which will be included in Spring Framework |
when i use
applicationContext.getBeansWithAnnotation(Extensions.class)
;in spring framework 5.3.20 , i can got a bean,
in spring framework 5.3.28, i can't got a bean.
definition of
Extensions
:Definition of variable "applicationContext":
Can someone tell me what changes have occurred here?
I think this should be a problem, but I couldn't find where the problem occurred.
The text was updated successfully, but these errors were encountered: