Skip to content

ArrayStoreException scanning subclassed enum annotation array with multiple values [SPR-10914] #15542

@spring-projects-issues

Description

@spring-projects-issues

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:

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)

Affects: 3.2.4

Attachments:

Referenced from: commits 8abe949, 7500cae

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions