Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions