Skip to content

java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy exception when annotation config not found needs to specify what class is not found [SPR-10441] #15074

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

Closed
spring-projects-issues opened this issue Apr 4, 2013 · 11 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 4, 2013

Hendy Irawan opened SPR-10441 and commented

It happened for me when I used Spring Configuration annotation like this:

@Configuration
@Import({ Config.class })
public class WebConfig extends WebMvcConfigurerAdapter
{
   ...
}

When I renamed Config.class to CoreConfig.class the error occurred when starting jetty. this happened because the CoreConfig.class was in a different sub module of my maven project, so jetty couldn't see it (as it resolves dependencies through mvn local repository).

After calling 'mvn install' everything was fine again.

This is a packaging problem on user's part. Some class is not on the classpath.

as described in http://stackoverflow.com/questions/11823288/java-lang-arraystoreexception-sun-reflect-annotation-typenotpresentexceptionpro

However the exception stacktrace does not mention what class cannot be found by Spring. So locating the culprit in a large project is very difficult and time consuming.

Spring should pinpoint the affected class, who loads that class, so app developer can fix it.

Exception in thread "main" java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673)
	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
	at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178)
	at java.lang.Class.getAnnotations(Class.java:3158)
	at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:159)
	at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:152)
	at org.springframework.core.annotation.AnnotatedElementUtils.isAnnotated(AnnotatedElementUtils.java:72)
	at org.springframework.core.type.StandardAnnotationMetadata.isAnnotated(StandardAnnotationMetadata.java:102)
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:72)
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:62)
	at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:140)
	at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:127)
	at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:122)
	at org.springframework.context.annotation.AnnotationConfigApplicationContext.register(AnnotationConfigApplicationContext.java:151)
	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:83)
	at org.springframework.issues.SampleApp.main(SampleApp.java:12)

Affects: 3.2.2

Issue Links:

Referenced from: commits ac61b13

0 votes, 6 watchers

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

I got hit by this again

Solution #1: Run mvn install

Solution #2: In Eclipse IDE, remove the webapp project (web resource) from Tomcat Server, then re-add.

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

-Could you provide a sample project or at least a full stack trace?-
See sample project: https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-10441

How is this workflow failing exactly? If I understand correctly, you have two modules and you are performing a refactoring that affects both modules: in module A you rename Config to CoreConfig and in module B you change the @Import statement to refer to CoreConfig.class.

This is compiling fine in your IDE but your jetty server is using a different classpath (the local repository and not the modified sources that have been compiled by your IDE.

Am I missing anything here? Thanks.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I haven't seen such an exception before, and I'm wondering how to arrive at such a state of things as well.

That said, it looks like we can code defensively in any case there, catching unexpected annotation lookup exceptions and rethrowing them with richer introspection context from our side.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

Simple way to reproduce:

@Configuration @Import(OtherConfig.class)
public class MyConfig {

Before running webserver (Tomcat, Jetty, anything), remove the "WEB-INF/classes/somepackage/OtherConfig.class" file. Then run.

The reason is Spring tries to call .getAnnotations() on the MyConfig class. However since it has @Import which refers to non-existing class OtherConfig, it throws error. Which is a valid error, however....

Without any clue to which class Spring is processing, it's hard to diagnose this problem for the app developer. So Spring should catch the Exception thrown by .getAnnotations() and wrap it with an error describing the class it is processing.

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

IMHO this is a specialization of ClassNotFoundException. However CNFE is quite helpful that it gives the name of the class not found. This exception doesn't give anything (neither "MyConfig" nor the "OtherConfig" class, nor the "Import" annotation).

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

Hendy, I have provided a sample project that can be used to reproduce the issue. Please have a look to it and confirm that's what you're having:
https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-10441

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

Stéphane Nicoll Yes exactly! :)

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

AnnotatedElementUtils wraps unexpected exceptions with a descriptive IllegalStateException now, including the AnnotatedElement (Class/Method) toString representation.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

Thank you Juergen Hoeller so much! awesome :)

@spring-projects-issues
Copy link
Collaborator Author

Ken Kruger commented

Juergen, Phil, Hendry - Thanks for discovering and fixing this issue. This improved debugging information just saved my bacon. I had no idea what was wrong using 4.0.2. Kudos.

@spring-projects-issues
Copy link
Collaborator Author

Tim Meighen commented

I think this issue may have cropped up again starting with 4.1.7.RELEASE. I'm having the problem with 4.3.2.RELEASE and came across this issue. I downloaded the sample issue here:

https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-10441

and I get the enhanced info up to 4.1.6.RELEASE:

Exception in thread "main" java.lang.IllegalStateException: Failed to introspect annotations: class org.springframework.issues.SampleApp$AppConfig
at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:166)
...

From 4.1.7.RELEASE onwards I no longer get the IllegalStateException and just get:

Exception in thread "main" java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants