diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java index 3577566e81..fbfc3a684d 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java @@ -28,7 +28,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.asm.AnnotationVisitor; import org.springframework.asm.SpringAsmInfo; import org.springframework.asm.Type; @@ -131,7 +130,13 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue); } else { - Object[] newArray = (Object[]) Array.newInstance(newValue.getClass(), 1); + Class arrayClass = newValue.getClass(); + if(Enum.class.isAssignableFrom(arrayClass)) { + while(arrayClass.getSuperclass() != null && !arrayClass.isEnum()) { + arrayClass = arrayClass.getSuperclass(); + } + } + Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1); newArray[0] = newValue; newValue = newArray; } diff --git a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java index 870ccd3bee..484f8207c5 100644 --- a/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/AnnotationMetadataTests.java @@ -98,7 +98,7 @@ public class AnnotationMetadataTests { assertThat(metadata.hasAnnotation(Component.class.getName()), is(true)); assertThat(metadata.hasAnnotation(Scope.class.getName()), is(true)); assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(true)); - assertThat(metadata.getAnnotationTypes().size(), is(5)); + assertThat(metadata.getAnnotationTypes().size(), is(6)); assertThat(metadata.getAnnotationTypes().contains(Component.class.getName()), is(true)); assertThat(metadata.getAnnotationTypes().contains(Scope.class.getName()), is(true)); assertThat(metadata.getAnnotationTypes().contains(SpecialAttr.class.getName()), is(true)); @@ -247,6 +247,20 @@ public class AnnotationMetadataTests { public @interface MetaMetaAnnotation { } + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + public @interface EnumSubclasses { + SubclassEnum[] value(); + } + + // SPR-10914 + public static enum SubclassEnum { + FOO { + }, + BAR { + }; + } + @Component("myName") @Scope("myScope") @SpecialAttr(clazz = String.class, state = Thread.State.NEW, @@ -258,6 +272,7 @@ public class AnnotationMetadataTests { @SuppressWarnings({"serial", "unused"}) @DirectAnnotation("direct") @MetaMetaAnnotation + @EnumSubclasses({ SubclassEnum.FOO, SubclassEnum.BAR }) private static class AnnotatedComponent implements Serializable { @TestAutowired