You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AnnotatedElementUtils fails to find annotations on abstract, bridge, or interface methods [SPR-12738] #17335
This was encountered while adding support for @RequestMapping as meta annotation. Following a change from AnnotationUtils.findAnnotation to AnnotatedElementUtils.getAnnotationAttributes, there are failing integration tests with controller hierarchies.
Analysis / Known Issues
AnnotatedElementUtils does not currently support interfaces or bridge methods in its search algorithms.
Deliverables
Support abstract methods in AnnotatedElementUtils.
Support interface methods in AnnotatedElementUtils.
Support bridge methods in AnnotatedElementUtils.
Support bridged methods in AnnotatedElementUtils.
Search for TODOs in AnnotatedElementUtilsTests and re-instate @Ignore'd tests.
Search for TODOs in TransactionalEventListenerTests and re-instate @Ignore'd tests.
For example, ServletAnnotationControllerHandlerMethodTests has a number of failures (that's in the temporary branch for @RequestMapping meta-annotation support).
Support abstract, bridge, & interface methods in AnnotatedElementUtils
This commit introduces support for finding annotations on abstract,
bridge, and interface methods in AnnotatedElementUtils.
Introduced dedicated findAnnotationAttributes() methods in
AnnotatedElementUtils that provide first-class support for
processing methods, class hierarchies, interfaces, bridge methods,
etc.
Introduced find/get search algorithm dichotomy in
AnnotatedElementUtils which is visible in the public API as well as
in the internal implementation. This was necessary in order to
maintain backwards compatibility with the existing API (even though
it was undocumented).
Reverted all recent changes made to the "get semantics" search
algorithm in AnnotatedElementUtils in order to ensure backwards
compatibility, and reverted recent changes to
JtaTransactionAnnotationParser and SpringTransactionAnnotationParser
accordingly.
To utilize these features, you will need to invoke AnnotatedElementUtils.findAnnotationAttributes(), notAnnotatedElementUtils.getAnnotationAttributes().
The existing getAnnotationAttributes() methods have been left in place and reworked so that they remain backwards compatible.
Basically, AnnotatedElementUtils supports finding annotations on a bridge method but not on a bridged method.
The test you introduced in AnnotatedElementUtilsTests (i.e., findAnnotationAttributesInheritedFromBridgedMethod()) is still @Ignore'd because it actually attempts to find an annotation on a bridged method. Note, however, that the newly introduced findAnnotationAttributesFromBridgeMethod() test works as expected.
Thus, I think your test might not adequately mimic what occurs at runtime. For example, in RequestMappingHandlerMapping it appears to me that all of the methods in a given candidate class will be iterated over reflectively. Thus annotated bridge methods should still be handled appropriately (I hope).
Can you please rebase your temporary branch against master and let me know if the new AnnotatedElementUtils.findAnnotationAttributes() method suits your needs?
Sam Brannen, I rebased my branch but still seeing the same failures. Would you take a look? Run the spring-webmvc tests and the failures are in MvcUriComponentsBuilderTests, ServletAnnotationControllerHandlerMethodTests, and HandlerMethodAnnotationDetectionTests.
Rossen Stoyanchev, I have not checked out your branch, but just by looking at the code on GitHub, I see that you are still invoking AnnotatedElementUtils.getAnnotationAttributes() which does not support the new search features.
Please switch to AnnotatedElementUtils.findAnnotationAttributes() (note the find) and let me know if that solves your problems!
Activity
spring-projects-issues commentedon Feb 20, 2015
Rossen Stoyanchev commented
Tests added in b94c6fd.
For example,
ServletAnnotationControllerHandlerMethodTestshas a number of failures (that's in the temporary branch for@RequestMappingmeta-annotation support).spring-projects-issues commentedon Apr 19, 2015
Sam Brannen commented
Potentially related commits to review:
spring-projects-issues commentedon Apr 22, 2015
Sam Brannen commented
FYI: support for finding annotations at the type level on interfaces is addressed by #17537.
spring-projects-issues commentedon Apr 23, 2015
Sam Brannen commented
Completed as described in GitHub commit ad6bea1:
spring-projects-issues commentedon Apr 23, 2015
Sam Brannen commented
Important
To utilize these features, you will need to invoke
AnnotatedElementUtils.findAnnotationAttributes(), notAnnotatedElementUtils.getAnnotationAttributes().The existing
getAnnotationAttributes()methods have been left in place and reworked so that they remain backwards compatible.spring-projects-issues commentedon Apr 23, 2015
Sam Brannen commented
Rossen Stoyanchev,
Note the (x) in this issue's description.
Basically,
AnnotatedElementUtilssupports finding annotations on a bridge method but not on a bridged method.The test you introduced in
AnnotatedElementUtilsTests(i.e.,findAnnotationAttributesInheritedFromBridgedMethod()) is still@Ignore'd because it actually attempts to find an annotation on a bridged method. Note, however, that the newly introducedfindAnnotationAttributesFromBridgeMethod()test works as expected.Thus, I think your test might not adequately mimic what occurs at runtime. For example, in
RequestMappingHandlerMappingit appears to me that all of the methods in a given candidate class will be iterated over reflectively. Thus annotated bridge methods should still be handled appropriately (I hope).Can you please rebase your temporary branch against master and let me know if the new
AnnotatedElementUtils.findAnnotationAttributes()method suits your needs?Thanks!
Sam
spring-projects-issues commentedon Apr 24, 2015
Rossen Stoyanchev commented
Sure I'll give it a try.
spring-projects-issues commentedon Apr 24, 2015
Rossen Stoyanchev commented
Sam Brannen, I rebased my branch but still seeing the same failures. Would you take a look? Run the spring-webmvc tests and the failures are in MvcUriComponentsBuilderTests, ServletAnnotationControllerHandlerMethodTests, and HandlerMethodAnnotationDetectionTests.
spring-projects-issues commentedon Apr 24, 2015
Sam Brannen commented
Rossen Stoyanchev, I have not checked out your branch, but just by looking at the code on GitHub, I see that you are still invoking
AnnotatedElementUtils.getAnnotationAttributes()which does not support the new search features.Please switch to
AnnotatedElementUtils.findAnnotationAttributes()(note the find) and let me know if that solves your problems!Thanks,
Sam
spring-projects-issues commentedon Apr 24, 2015
Rossen Stoyanchev commented
All green!
spring-projects-issues commentedon Apr 24, 2015
Sam Brannen commented
Awesome! :)
Thanks for letting me know.