mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 21:39:05 +00:00
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:
+11
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user