Skip to content

Commit 0637864

Browse files
committed
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
1 parent 0f5a27c commit 0637864

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,19 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
278278
Set<Annotation> visited) {
279279
Assert.notNull(clazz, "Class must not be null");
280280

281-
A annotation = clazz.getDeclaredAnnotation(annotationType);
282-
if (annotation != null) {
283-
return annotation;
281+
if (isAnnotationDeclaredLocally(annotationType, clazz)) {
282+
return clazz.getAnnotation(annotationType);
284283
}
285284
for (Class<?> ifc : clazz.getInterfaces()) {
286-
annotation = findAnnotation(ifc, annotationType, visited);
285+
A annotation = findAnnotation(ifc, annotationType, visited);
287286
if (annotation != null) {
288287
return annotation;
289288
}
290289
}
291290
for (Annotation ann : clazz.getDeclaredAnnotations()) {
292291
if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) {
293-
annotation = findAnnotation(ann.annotationType(), annotationType, visited);
292+
A annotation = findAnnotation(ann.annotationType(), annotationType,
293+
visited);
294294
if (annotation != null) {
295295
return annotation;
296296
}

0 commit comments

Comments
 (0)