Eliminate inspection of annotations on core Java annotations

This commit picks up where SPR-11483 left off, with the goal of
eliminating all unnecessary inspection of core JDK annotations in
Spring's annotation search algorithms in AnnotatedElementUtils and
AnnotationMetadataReadingVisitor.

Issue: SPR-12989
This commit is contained in:
Sam Brannen
2015-05-06 00:17:12 +02:00
parent ba84458c65
commit 5d67219a4e
5 changed files with 22 additions and 9 deletions

View File

@@ -406,8 +406,8 @@ public class AnnotatedElementUtils {
// Search in local annotations
for (Annotation annotation : annotations) {
// TODO Test for !AnnotationUtils.isInJavaLangAnnotationPackage(annotation)
if (annotation.annotationType().getName().equals(annotationType) || metaDepth > 0) {
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)
&& (annotation.annotationType().getName().equals(annotationType) || metaDepth > 0)) {
T result = processor.process(annotation, metaDepth);
if (result != null) {
return result;

View File

@@ -636,7 +636,19 @@ public abstract class AnnotationUtils {
*/
public static boolean isInJavaLangAnnotationPackage(Annotation annotation) {
Assert.notNull(annotation, "Annotation must not be null");
return annotation.annotationType().getName().startsWith("java.lang.annotation");
return isInJavaLangAnnotationPackage(annotation.annotationType().getName());
}
/**
* Determine if the {@link Annotation} with the supplied name is defined
* in the core JDK {@code java.lang.annotation} package.
* @param annotationType the name of the annotation type to check (never {@code null} or empty)
* @return {@code true} if the annotation is in the {@code java.lang.annotation} package
* @since 4.2
*/
public static boolean isInJavaLangAnnotationPackage(String annotationType) {
Assert.hasText(annotationType, "annotationType must not be null or empty");
return annotationType.startsWith("java.lang.annotation");
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -28,6 +28,7 @@ import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
import org.springframework.asm.Type;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.util.LinkedMultiValueMap;
@@ -114,7 +115,7 @@ public class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisito
@Override
public boolean isAnnotated(String annotationType) {
return this.attributesMap.containsKey(annotationType);
return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationType) && this.attributesMap.containsKey(annotationType));
}
@Override