Support nested annotations in ASM-based processing again
Spring Framework 5.0 introduced a regression in ASM-based annotation processing. Specifically, nested annotations were no longer supported, and component scanning resulted in an exception if a candidate component was annotated with an annotation that contained nested annotations. This commit fixes this regression by introducing special handling in AnnotationTypeMapping that supports extracting values from objects of type TypeMappedAnnotation when necessary. Closes gh-24375
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,7 +47,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
final class AnnotationTypeMapping {
|
||||
|
||||
|
||||
private static final MirrorSet[] EMPTY_MIRROR_SETS = new MirrorSet[0];
|
||||
|
||||
|
||||
@@ -534,8 +533,15 @@ final class AnnotationTypeMapping {
|
||||
AttributeMethods attributes = AttributeMethods.forAnnotationType(annotation.annotationType());
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
Method attribute = attributes.get(i);
|
||||
if (!areEquivalent(ReflectionUtils.invokeMethod(attribute, annotation),
|
||||
valueExtractor.apply(attribute, extractedValue), valueExtractor)) {
|
||||
Object value1 = ReflectionUtils.invokeMethod(attribute, annotation);
|
||||
Object value2;
|
||||
if (extractedValue instanceof TypeMappedAnnotation) {
|
||||
value2 = ((TypeMappedAnnotation<?>) extractedValue).getValue(attribute.getName()).orElse(null);
|
||||
}
|
||||
else {
|
||||
value2 = valueExtractor.apply(attribute, extractedValue);
|
||||
}
|
||||
if (!areEquivalent(value1, value2, valueExtractor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
private static Object extractFromMap(Method attribute, @Nullable Object map) {
|
||||
static Object extractFromMap(Method attribute, @Nullable Object map) {
|
||||
return (map != null ? ((Map<String, ?>) map).get(attribute.getName()) : null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user