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
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.
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
Ensure that an explicit annotation attribute override configured via @AliasFor is only applied to the configured target meta-annotation.
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).
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 thelocations
attribute in@ContextConfiguration
, effectively renaming it.@MyTestConfig
works fine as long as there is not more than one meta-annotation with an attribute namedlocations
.In contrast, the following currently does not work.
The reason is that the
getAliasedAttributeName(Method attribute, Class<? extends Annotation> targetAnnotationType)
method inAnnotationUtils
does not verify that the suppliedattribute
actually declares an alias for thetargetAnnotationType
. Consequently, a lookup for thelocations
attribute in@TestPropertySource
onMyTests
will incorrectly return"test.xml"
instead of"test.properties"
.Deliverables
@AliasFor
is only applied to the configured target meta-annotation.Affects: 4.2 GA
Issue Links:
@AliasFor
("is depended on by")Referenced from: commits e20b47c, c8d604b
The text was updated successfully, but these errors were encountered: