Skip to content
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

Favor more locally declared composed annotations over inherited annotations in the TestContext framework [SPR-12749] #17346

Closed
spring-issuemaster opened this issue Feb 24, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 24, 2015

David Erickson opened SPR-12749 and commented

Specific case: a test class is annotated with a meta annotation that itself is annotated with a TestExecutionListeners annotation, and the test class also extends a parent class annotated with a TestExecutionListeners annotation (say AbstractJunit4SpringContextTests).

In this case, MetaAnnotationUtils.findAnnotationDescriptor returns a AnnotationDescriptor class that is correct on all of its fields, except for getAnnotationAttributes(), which is incorrectly returning the attributes of the TestExecutionListeners from the parent class, rather than the meta annotation, which is incorrect based on the description of MetaAnnotationUtils.findAnnotationDescriptor:

The algorithm operates as follows:

Search for the annotation on the given class and return a corresponding AnnotationDescriptor if found.
Recursively search through all annotations that the given class declares.
Recursively search through the superclass hierarchy of the given class.

The net result being the test framework does not pick up my declared TestExecutionListeners from the meta annotation any time a parent of the Test class also declares TestExecutionListeners. I added a spring-framework-issues reproducible project to demonstrate the issue.


Affects: 4.1.4

Reference URL: spring-projects/spring-framework-issues#92

Issue Links:

  • #18245 @ContextConfiguration defined on a base class and a composed annotation do not merge ("is duplicated by")
  • #18321 ActiveProfiles not included when using a custom annotation. ("is duplicated by")
  • #16221 Favor more locally declared composed annotations over inherited annotations
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 24, 2015

Sam Brannen commented

I will investigate this issue in detail in the coming weeks; however, please note that this is very likely a duplicate of #16221.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 24, 2015

David Erickson commented

Agreed, it does sound very similar.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 22, 2015

Sam Brannen commented

Although #16221 will cover such support in a generic fashion across the framework, I have already implemented a fix that is local to the spring-test module as described in the comments for GitHub commit 69b0791:

Favor local, composed annotations in the TCF

Prior to this commit, AnnotationAttributes retrieved from
MetaAnnotationUtils's AnnotationDescriptor could contain attributes
from the wrong annotation if an inherited annotation shadowed a locally
declared composed annotation.

This commit addresses this issue by invoking the new
getAnnotationAttributes() method in AnnotatedElementUtils that provides
a flag to control whether superclasses should be searched -- which
coincidentally processes local annotations before searching the class
hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.