Moved AnnotationBeanNameGenerator's String value check right before cast

Issue: SPR-11221
This commit is contained in:
Juergen Hoeller
2013-12-17 12:39:24 +01:00
parent 078d2fe0e2
commit 23546b1234
3 changed files with 50 additions and 12 deletions

View File

@@ -89,13 +89,16 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
for (String type : types) {
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type);
if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
String value = (String) attributes.get("value");
if (StringUtils.hasLength(value)) {
if (beanName != null && !value.equals(beanName)) {
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
"component names: '" + beanName + "' versus '" + value + "'");
Object value = attributes.get("value");
if (value instanceof String) {
String strVal = (String) value;
if (StringUtils.hasLength(strVal)) {
if (beanName != null && !strVal.equals(beanName)) {
throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
"component names: '" + beanName + "' versus '" + strVal + "'");
}
beanName = strVal;
}
beanName = value;
}
}
}
@@ -118,9 +121,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
annotationType.equals("javax.annotation.ManagedBean") ||
annotationType.equals("javax.inject.Named");
return (isStereotype && attributes != null &&
attributes.containsKey("value") &&
attributes.get("value") instanceof String);
return (isStereotype && attributes != null && attributes.containsKey("value"));
}
/**