Avoid unnecessary annotation introspection on framework methods
Issue: SPR-16933
This commit is contained in:
@@ -228,8 +228,8 @@ public abstract class AnnotatedElementUtils {
|
||||
return hasMetaAnnotationTypes(element, null, annotationName);
|
||||
}
|
||||
|
||||
private static boolean hasMetaAnnotationTypes(AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType,
|
||||
@Nullable String annotationName) {
|
||||
private static boolean hasMetaAnnotationTypes(
|
||||
AnnotatedElement element, @Nullable Class<? extends Annotation> annotationType, @Nullable String annotationName) {
|
||||
|
||||
return Boolean.TRUE.equals(
|
||||
searchWithGetSemantics(element, annotationType, annotationName, new SimpleAnnotationProcessor<Boolean>() {
|
||||
@@ -680,6 +680,11 @@ public abstract class AnnotatedElementUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcut: no non-java annotations to be found on plain Java classes and org.springframework.lang types...
|
||||
if (AnnotationUtils.hasPlainJavaAnnotationsOnly(element) && !annotationType.getName().startsWith("java")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Exhaustive retrieval of merged annotation attributes...
|
||||
AnnotationAttributes attributes = findMergedAnnotationAttributes(element, annotationType, false, false);
|
||||
return (attributes != null ? AnnotationUtils.synthesizeAnnotation(attributes, annotationType, element) : null);
|
||||
@@ -1007,7 +1012,7 @@ public abstract class AnnotatedElementUtils {
|
||||
|
||||
if (containerType != null && !processor.aggregates()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Searches for repeatable annotations must supply an aggregating Processor");
|
||||
"Searches for repeatable annotations must supply an aggregating Processor");
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -641,11 +641,13 @@ public abstract class AnnotationUtils {
|
||||
if (anns.length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (anns.length == 1) {
|
||||
Class<?> annType = anns[0].annotationType();
|
||||
return (annType != Nullable.class && annType != Deprecated.class);
|
||||
for (Annotation ann : anns) {
|
||||
String name = ann.annotationType().getName();
|
||||
if (!name.startsWith("java.lang.") && !name.startsWith("org.springframework.lang.")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isOverride(Method method, Method candidate) {
|
||||
@@ -920,11 +922,11 @@ public abstract class AnnotationUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the {@link Annotation} with the supplied name is defined in the
|
||||
* {@code java.lang.annotation} or {@code org.springframework.lang} package.
|
||||
* @param annotatedElement the potential annotation type to check
|
||||
* @return {@code true} if the annotation is in the {@code java.lang.annotation}
|
||||
* or {@code org.springframework.lang} package
|
||||
* Determine if the given annotated element is defined in a
|
||||
* {@code java} or in the {@code org.springframework.lang} package.
|
||||
* @param annotatedElement the annotated element to check
|
||||
* @return {@code true} if the given element is in a {@code java}
|
||||
* package or in the {@code org.springframework.lang} package
|
||||
* @since 5.1
|
||||
*/
|
||||
static boolean hasPlainJavaAnnotationsOnly(@Nullable Object annotatedElement) {
|
||||
|
||||
Reference in New Issue
Block a user