Skip to content

Defensive error reporting when ConfigurationClassParser introspects declared methods via StandardAnnotationMetadata [SPR-13791] #18364

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 Dec 14, 2015 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 14, 2015

Dave Syer opened SPR-13791 and commented

When there is a class missing from the classpath that is needed by some annotation metadata, the app blows up deep in the java.lang.Class. The exception is hard to interpret for Spring users because there is no indication what it was trying to do when it failed. Example:

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:467)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/apache/thrift/TException
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:146)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:291)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:231)
...

where it is clear that the classpath is missing something, but not why, because Spring never tells us what it was doing, so we never find out what class it was trying to introspect (probably some autconfig from Spring Boot in this case, but it's hard to say). Maybe ConfigurationClassParser or StandardAnnotationMetadata could catch the exception and rethrow with a message that indicates what they were doing at the time?


Affects: 4.1.8, 4.2.3

Issue Links:

Referenced from: commits a36c0a5, bc492b9

Backported to: 4.1.9

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We're catching any Throwable there now, re-throwing it as an IllegalStateException which indicates that we were trying to introspect annotated methods on a particular class.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

Splendid!

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) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants