Skip to content

Commit a066143

Browse files
committed
Polishing
This commit removes unnecessary not-null checks for annotation attribute alias names.
1 parent 164bed5 commit a066143

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AbstractAliasAwareAnnotationAttributeExtractor.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,23 @@ public final Object getAttributeValue(Method attributeMethod) {
9191
if (aliasNames != null) {
9292
final Object defaultValue = AnnotationUtils.getDefaultValue(getAnnotationType(), attributeName);
9393
for (String aliasName : aliasNames) {
94-
if (aliasName != null) {
95-
Object aliasValue = getRawAttributeValue(aliasName);
96-
97-
if (!ObjectUtils.nullSafeEquals(attributeValue, aliasValue) &&
98-
!ObjectUtils.nullSafeEquals(attributeValue, defaultValue) &&
99-
!ObjectUtils.nullSafeEquals(aliasValue, defaultValue)) {
100-
String elementName = (getAnnotatedElement() != null ? getAnnotatedElement().toString() : "unknown element");
101-
throw new AnnotationConfigurationException(String.format(
102-
"In annotation [%s] declared on %s and synthesized from [%s], attribute '%s' and its " +
103-
"alias '%s' are present with values of [%s] and [%s], but only one is permitted.",
104-
getAnnotationType().getName(), elementName, getSource(), attributeName, aliasName,
105-
ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue)));
106-
}
107-
108-
// If the user didn't declare the annotation with an explicit value,
109-
// use the value of the alias instead.
110-
if (ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) {
111-
attributeValue = aliasValue;
112-
}
94+
Object aliasValue = getRawAttributeValue(aliasName);
95+
96+
if (!ObjectUtils.nullSafeEquals(attributeValue, aliasValue) &&
97+
!ObjectUtils.nullSafeEquals(attributeValue, defaultValue) &&
98+
!ObjectUtils.nullSafeEquals(aliasValue, defaultValue)) {
99+
String elementName = (getAnnotatedElement() != null ? getAnnotatedElement().toString() : "unknown element");
100+
throw new AnnotationConfigurationException(String.format(
101+
"In annotation [%s] declared on %s and synthesized from [%s], attribute '%s' and its " +
102+
"alias '%s' are present with values of [%s] and [%s], but only one is permitted.",
103+
getAnnotationType().getName(), elementName, getSource(), attributeName, aliasName,
104+
ObjectUtils.nullSafeToString(attributeValue), ObjectUtils.nullSafeToString(aliasValue)));
105+
}
106+
107+
// If the user didn't declare the annotation with an explicit value,
108+
// use the value of the alias instead.
109+
if (ObjectUtils.nullSafeEquals(attributeValue, defaultValue)) {
110+
attributeValue = aliasValue;
113111
}
114112
}
115113
}

spring-core/src/main/java/org/springframework/core/annotation/MapAnnotationAttributeExtractor.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ private static Map<String, Object> enrichAndValidateAttributes(
9999
List<String> aliasNames = attributeAliasMap.get(attributeName);
100100
if (aliasNames != null) {
101101
for (String aliasName : aliasNames) {
102-
if (aliasName != null) {
103-
Object aliasValue = attributes.get(aliasName);
104-
if (aliasValue != null) {
105-
attributeValue = aliasValue;
106-
attributes.put(attributeName, attributeValue);
107-
break;
108-
}
102+
Object aliasValue = attributes.get(aliasName);
103+
if (aliasValue != null) {
104+
attributeValue = aliasValue;
105+
attributes.put(attributeName, attributeValue);
106+
break;
109107
}
110108
}
111109
}

0 commit comments

Comments
 (0)