Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Sep 13, 2013 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2.5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants