From 7ad6df8c750445c8b608d3b1ae525d0a3a5072ec Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 20 Dec 2013 00:02:27 +0100 Subject: [PATCH] Moved AnnotationBeanNameGenerator's String value check right before cast Issue: SPR-11221 --- .../AnnotationBeanNameGenerator.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java index 8df47ec0e1..a3d0d72555 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java @@ -88,13 +88,16 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { for (String type : types) { AnnotationAttributes attributes = MetadataUtils.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; } } } @@ -117,9 +120,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")); } /**