Skip annotations that cannot be processed in AnnotationBeanNameGenerator

Prior to this commit, AnnotationBeanNameGenerator failed when searching
for a convention-based bean name, if an annotation referenced a
non-existent class.

To address that, this commit introduces a try-catch block around each
invocation of MergedAnnotation.asAnnotationAttributes() and skips
processing of the current MergedAnnotation if an exception occurs,
which is likely due to a type referenced from an annotation attribute
not being present in the classpath.

See gh-31203
Closes gh-36524

(cherry picked from commit 00fbd91cca)
This commit is contained in:
Sam Brannen
2026-04-02 16:57:09 +02:00
parent 684b1e8a4b
commit d78d80b02a
2 changed files with 65 additions and 1 deletions
@@ -143,7 +143,17 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
Set<AnnotationAttributes> visited = new HashSet<>();
for (MergedAnnotation<Annotation> mergedAnnotation : mergedAnnotations) {
AnnotationAttributes attributes = mergedAnnotation.asAnnotationAttributes(ADAPTATIONS);
AnnotationAttributes attributes = null;
try {
attributes = mergedAnnotation.asAnnotationAttributes(ADAPTATIONS);
}
catch (Throwable ex) {
// Ignore exception and current MergedAnnotation, assuming that values of the
// MergedAnnotation could not be adapted to a Map/AnnotationAttributes due to
// missing types referenced via annotation attributes.
continue;
}
if (visited.add(attributes)) {
String annotationType = mergedAnnotation.getType().getName();
Set<String> metaAnnotationTypes = this.metaAnnotationTypesCache.computeIfAbsent(annotationType,