Spring's class reading code has a bug as follows: when an annotation is encountered where the annotation value has type array of some enum, Spring creates an array having type "array of X" where "X" is the type of the first encountered enum value. But in cases where the enum values are extensions (subclasses) of the enum type, and there are multiple values in the array,
this causes an ArrayStoreException, because the array element type is too narrow, being that of the first enum value rather than the overall enum type.
The attached test case demonstrates the problem, for example:
Exception in thread "main" java.lang.ArrayStoreException: Bug$BugEnum$2
at org.springframework.util.ObjectUtils.addObjectToArray(ObjectUtils.java:194)
at org.springframework.core.type.classreading.RecursiveAnnotationArrayVisitor.visit(AnnotationAttributesReadingVisitor.java:122)
at org.springframework.core.type.classreading.AbstractRecursiveAnnotationVisitor.visitEnum(AnnotationAttributesReadingVisitor.java:77)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:64)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at Bug.main(Bug.java:7)
Archie Cobbs opened SPR-10914 and commented
Spring's class reading code has a bug as follows: when an annotation is encountered where the annotation value has type array of some enum, Spring creates an array having type "array of X" where "X" is the type of the first encountered enum value. But in cases where the enum values are extensions (subclasses) of the enum type, and there are multiple values in the array,
this causes an
ArrayStoreException
, because the array element type is too narrow, being that of the first enum value rather than the overall enum type.The attached test case demonstrates the problem, for example:
Affects: 3.2.4
Attachments:
Referenced from: commits 8abe949, 7500cae
The text was updated successfully, but these errors were encountered: