From 0637864b3909ab13727cb228258b778a265da8d9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 26 Feb 2014 17:51:26 +0100 Subject: [PATCH] Ensure AnnotationUtils is compatible with Java 6 The previous commit introduced a dependency on Class.getDeclaredAnnotation() which is a Java 8 API. This commit refactors AnnotationUtils.findAnnotation(Class, Class, Set) to use Class.getAnnotation() in conjunction with isAnnotationDeclaredLocally() in order to achieve the same desired behavior. Issue: SPR-11475 --- .../core/annotation/AnnotationUtils.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 3061648a25e..f09f09709cc 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -278,19 +278,19 @@ public abstract class AnnotationUtils { Set visited) { Assert.notNull(clazz, "Class must not be null"); - A annotation = clazz.getDeclaredAnnotation(annotationType); - if (annotation != null) { - return annotation; + if (isAnnotationDeclaredLocally(annotationType, clazz)) { + return clazz.getAnnotation(annotationType); } for (Class ifc : clazz.getInterfaces()) { - annotation = findAnnotation(ifc, annotationType, visited); + A annotation = findAnnotation(ifc, annotationType, visited); if (annotation != null) { return annotation; } } for (Annotation ann : clazz.getDeclaredAnnotations()) { if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) { - annotation = findAnnotation(ann.annotationType(), annotationType, visited); + A annotation = findAnnotation(ann.annotationType(), annotationType, + visited); if (annotation != null) { return annotation; }