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-issuemaster opened this issue Sep 13, 2013 · 0 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Sep 13, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.