Fix ArrayStoreException reading subclassed enums
Fix ASM AnnotationAttributesReadingVisitor to correctly deal with subclasses enums. Issue: SPR-10914
This commit is contained in:
parent
f3611e767e
commit
8abe949734
|
@ -28,7 +28,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.asm.AnnotationVisitor;
|
import org.springframework.asm.AnnotationVisitor;
|
||||||
import org.springframework.asm.SpringAsmInfo;
|
import org.springframework.asm.SpringAsmInfo;
|
||||||
import org.springframework.asm.Type;
|
import org.springframework.asm.Type;
|
||||||
|
@ -131,7 +130,13 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
|
||||||
newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
|
newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
newArray[0] = newValue;
|
||||||
newValue = newArray;
|
newValue = newArray;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class AnnotationMetadataTests {
|
||||||
assertThat(metadata.hasAnnotation(Component.class.getName()), is(true));
|
assertThat(metadata.hasAnnotation(Component.class.getName()), is(true));
|
||||||
assertThat(metadata.hasAnnotation(Scope.class.getName()), is(true));
|
assertThat(metadata.hasAnnotation(Scope.class.getName()), is(true));
|
||||||
assertThat(metadata.hasAnnotation(SpecialAttr.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(Component.class.getName()), is(true));
|
||||||
assertThat(metadata.getAnnotationTypes().contains(Scope.class.getName()), is(true));
|
assertThat(metadata.getAnnotationTypes().contains(Scope.class.getName()), is(true));
|
||||||
assertThat(metadata.getAnnotationTypes().contains(SpecialAttr.class.getName()), is(true));
|
assertThat(metadata.getAnnotationTypes().contains(SpecialAttr.class.getName()), is(true));
|
||||||
|
@ -247,6 +247,20 @@ public class AnnotationMetadataTests {
|
||||||
public @interface MetaMetaAnnotation {
|
public @interface MetaMetaAnnotation {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface EnumSubclasses {
|
||||||
|
SubclassEnum[] value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPR-10914
|
||||||
|
public static enum SubclassEnum {
|
||||||
|
FOO {
|
||||||
|
},
|
||||||
|
BAR {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Component("myName")
|
@Component("myName")
|
||||||
@Scope("myScope")
|
@Scope("myScope")
|
||||||
@SpecialAttr(clazz = String.class, state = Thread.State.NEW,
|
@SpecialAttr(clazz = String.class, state = Thread.State.NEW,
|
||||||
|
@ -258,6 +272,7 @@ public class AnnotationMetadataTests {
|
||||||
@SuppressWarnings({"serial", "unused"})
|
@SuppressWarnings({"serial", "unused"})
|
||||||
@DirectAnnotation("direct")
|
@DirectAnnotation("direct")
|
||||||
@MetaMetaAnnotation
|
@MetaMetaAnnotation
|
||||||
|
@EnumSubclasses({ SubclassEnum.FOO, SubclassEnum.BAR })
|
||||||
private static class AnnotatedComponent implements Serializable {
|
private static class AnnotatedComponent implements Serializable {
|
||||||
|
|
||||||
@TestAutowired
|
@TestAutowired
|
||||||
|
|
Loading…
Reference in New Issue