Consistent exposure of empty attribute arrays in AnnotationMetadata
Issue: SPR-17347
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -82,6 +83,20 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor
|
||||
if (!this.allNestedAttributes.isEmpty()) {
|
||||
this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0]));
|
||||
}
|
||||
else if (!this.attributes.containsKey(this.attributeName)) {
|
||||
Class<? extends Annotation> annotationType = this.attributes.annotationType();
|
||||
if (annotationType != null) {
|
||||
try {
|
||||
Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType();
|
||||
if (attributeType.isArray()) {
|
||||
this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0));
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// Corresponding attribute method not found: cannot expose empty array.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user