Overview
While working on #36586, we noticed that we use ClassUtils.resolveClassName() in TypeMappedAnnotation.adapt(...) which throws an IllegalStateException or IllegalArgumentException if a type referenced by an annotation attribute cannot be loaded. I also noticed that we have similar behavior in MergedAnnotationReadingVisitor and ClassFileAnnotationDelegate.
However, if such an error occurs while using the JDK's reflection APIs, a TypeNotPresentException is thrown instead.
We should therefore align with the standard behavior of the JDK and throw a TypeNotPresentException in such scenarios.
Related Issues
Overview
While working on #36586, we noticed that we use
ClassUtils.resolveClassName()inTypeMappedAnnotation.adapt(...)which throws anIllegalStateExceptionorIllegalArgumentExceptionif a type referenced by an annotation attribute cannot be loaded. I also noticed that we have similar behavior inMergedAnnotationReadingVisitorandClassFileAnnotationDelegate.However, if such an error occurs while using the JDK's reflection APIs, a
TypeNotPresentExceptionis thrown instead.We should therefore align with the standard behavior of the JDK and throw a
TypeNotPresentExceptionin such scenarios.Related Issues
MergedAnnotation.asMap()fails when an attribute references a non-existent class #36586