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

@AliasFor potentially overrides attribute in wrong meta-annotation [SPR-13325] #17910

Closed
spring-projects-issues opened this issue Aug 6, 2015 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Aug 6, 2015

Sam Brannen opened SPR-13325 and commented

Status Quo

Spring Framework 4.2 introduced support for explicit attribute overrides in meta-annotations via the @AliasFor annotation.

For example, the following @MyTestConfig annotation uses @AliasFor to explicitly override the locations attribute in @ContextConfiguration, effectively renaming it.

@ContextConfiguration
public @interface MyTestConfig {

    @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
    String[] xmlFiles();
 }

@MyTestConfig works fine as long as there is not more than one meta-annotation with an attribute named locations.

In contrast, the following currently does not work.

@ContextConfiguration
@TestPropertySource(locations = "test.properties")
public @interface MyCombinedTestConfig {

    @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
    String[] xmlFiles();
}
@MyCombinedTestConfig(xmlFiles = "test.xml")
public class MyTests {
    // ...
}

The reason is that the getAliasedAttributeName(Method attribute, Class<? extends Annotation> targetAnnotationType) method in AnnotationUtils does not verify that the supplied attribute actually declares an alias for the targetAnnotationType. Consequently, a lookup for the locations attribute in @TestPropertySource on MyTests will incorrectly return "test.xml" instead of "test.properties".

Deliverables

  1. Ensure that an explicit annotation attribute override configured via @AliasFor is only applied to the configured target meta-annotation.

Affects: 4.2 GA

Issue Links:

Referenced from: commits e20b47c, c8d604b

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Fixed as described in GitHub commit c8d604b:

Ensure @AliasFor overrides attribute in correct meta-annotation

Prior to this commit, an explicit override for an attribute in a meta-annotation configured via @AliasFor could potentially result in an incorrect override of an attribute of the same name but in the wrong meta-annotation.

This commit fixes the algorithm in getAliasedAttributeName(Method, Class) in AnnotationUtils by ensuring that an explicit attribute override is only applied to the configured target meta-annotation (i.e., configured via the annotation attribute in @AliasFor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants