Tolerate unidirectional alias declaration for annotation attribute pair

Closes gh-23834
This commit is contained in:
Juergen Hoeller
2019-10-30 14:31:09 +01:00
parent dba7bf7ec1
commit 42e7ade110
5 changed files with 69 additions and 167 deletions

View File

@@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
@@ -179,30 +178,25 @@ final class AnnotationTypeMapping {
}
if (isAliasPair(target) && checkAliasPair) {
AliasFor targetAliasFor = target.getAnnotation(AliasFor.class);
if (targetAliasFor == null) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName()));
}
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
if (!mirror.equals(attribute)) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
if (targetAliasFor != null) {
Method mirror = resolveAliasTarget(target, targetAliasFor, false);
if (!mirror.equals(attribute)) {
throw new AnnotationConfigurationException(String.format(
"%s must be declared as an @AliasFor '%s', not '%s'.",
StringUtils.capitalize(AttributeMethods.describe(target)),
attribute.getName(), mirror.getName()));
}
}
}
return target;
}
private boolean isAliasPair(Method target) {
return target.getDeclaringClass().equals(this.annotationType);
return (this.annotationType == target.getDeclaringClass());
}
private boolean isCompatibleReturnType(Class<?> attributeType, Class<?> targetType) {
return Objects.equals(attributeType, targetType) ||
Objects.equals(attributeType, targetType.getComponentType());
return (attributeType == targetType || attributeType == targetType.getComponentType());
}
private void processAliases() {