Skip to content

Commit 7ad6df8

Browse files
committed
Moved AnnotationBeanNameGenerator's String value check right before cast
Issue: SPR-11221
1 parent f5d5882 commit 7ad6df8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotat
8888
for (String type : types) {
8989
AnnotationAttributes attributes = MetadataUtils.attributesFor(amd, type);
9090
if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
91-
String value = (String) attributes.get("value");
92-
if (StringUtils.hasLength(value)) {
93-
if (beanName != null && !value.equals(beanName)) {
94-
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
95-
"component names: '" + beanName + "' versus '" + value + "'");
91+
Object value = attributes.get("value");
92+
if (value instanceof String) {
93+
String strVal = (String) value;
94+
if (StringUtils.hasLength(strVal)) {
95+
if (beanName != null && !strVal.equals(beanName)) {
96+
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
97+
"component names: '" + beanName + "' versus '" + strVal + "'");
98+
}
99+
beanName = strVal;
96100
}
97-
beanName = value;
98101
}
99102
}
100103
}
@@ -117,9 +120,7 @@ protected boolean isStereotypeWithNameValue(String annotationType,
117120
annotationType.equals("javax.annotation.ManagedBean") ||
118121
annotationType.equals("javax.inject.Named");
119122

120-
return (isStereotype && attributes != null &&
121-
attributes.containsKey("value") &&
122-
attributes.get("value") instanceof String);
123+
return (isStereotype && attributes != null && attributes.containsKey("value"));
123124
}
124125

125126
/**

0 commit comments

Comments
 (0)