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).

Issue: SPR-13325
This commit is contained in:
Sam Brannen
2015-08-06 19:04:08 +02:00
parent 1a659e3c1d
commit c8d604bf05
3 changed files with 62 additions and 0 deletions

View File

@@ -1465,6 +1465,11 @@ public abstract class AnnotationUtils {
boolean sameTargetDeclared =
(sourceAnnotationType.equals(aliasedAnnotationType) || Annotation.class.equals(aliasedAnnotationType));
// Explicit alias for a different target meta-annotation?
if (!searchWithinSameAnnotation && !targetAnnotationType.equals(aliasedAnnotationType)) {
return null;
}
// Wrong search scope?
if (searchWithinSameAnnotation && !sameTargetDeclared) {
return null;