Skip to content

AnnotationUtils.findAnnotation fails with poor diagnostics if it encounters an Annotation that references an unloadable class [SPR-11874] #16493

Closed
@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-11874 and commented

We've hit this problem quite a few times recently with Boot's @ConditionalOnClass, @ConditionalOnMissingClass, @ConditionalOnBean, and @ConditionalOnMissingBean. They can all take a Class.

If Spring introspects a class or method with one of these annotations and the class that's referenced by the Annotation cannot be loaded it fails with java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy and no information at all about what class could not be loaded. I don't think Spring can do anything about the lack of information about the class, but it could provide clearer information about which class/method was being introspected at the time of the failure.

We (the Boot team) have wondered if Spring should be using ASM-based annotation detection to avoid this problem altogether. An argument against this is that something else in the stack may well fail ungracefully even if Spring doesn't. In the case of the Boot conditions the problem's isolated to @Configuration classes. Could that reduce the chance of something else failing in a similar way and make it worthwhile to change Spring's behaviour?


Affects: 4.0.5

Reference URL: spring-projects/spring-boot#1065

Issue Links:

Referenced from: commits 74c878e, 2c0c081, fd809cd

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions