Skip to content

Commit 7e38f47

Browse files
committed
Polishing
1 parent 42a3634 commit 7e38f47

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,30 +268,29 @@ public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> a
268268
/**
269269
* Perform the search algorithm for {@link #findAnnotation(Class, Class)},
270270
* avoiding endless recursion by tracking which annotations have already
271-
* been visited.
271+
* been <em>visited</em>.
272272
* @param clazz the class to look for annotations on
273273
* @param annotationType the type of annotation to look for
274-
* @param visitedAnnotations the set of annotations that have already been visited
274+
* @param visited the set of annotations that have already been visited
275275
* @return the annotation if found, or {@code null} if not found
276276
*/
277277
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType,
278-
Set<Annotation> visitedAnnotations) {
278+
Set<Annotation> visited) {
279279
Assert.notNull(clazz, "Class must not be null");
280280

281281
A annotation = clazz.getAnnotation(annotationType);
282282
if (annotation != null) {
283283
return annotation;
284284
}
285285
for (Class<?> ifc : clazz.getInterfaces()) {
286-
annotation = findAnnotation(ifc, annotationType, visitedAnnotations);
286+
annotation = findAnnotation(ifc, annotationType, visited);
287287
if (annotation != null) {
288288
return annotation;
289289
}
290290
}
291291
for (Annotation ann : clazz.getAnnotations()) {
292-
if (!visitedAnnotations.contains(ann)) {
293-
visitedAnnotations.add(ann);
294-
annotation = findAnnotation(ann.annotationType(), annotationType, visitedAnnotations);
292+
if (visited.add(ann)) {
293+
annotation = findAnnotation(ann.annotationType(), annotationType, visited);
295294
if (annotation != null) {
296295
return annotation;
297296
}
@@ -301,7 +300,7 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
301300
if (superclass == null || superclass.equals(Object.class)) {
302301
return null;
303302
}
304-
return findAnnotation(superclass, annotationType, visitedAnnotations);
303+
return findAnnotation(superclass, annotationType, visited);
305304
}
306305

307306
/**
@@ -648,7 +647,7 @@ private A[] getValue(Annotation annotation) {
648647
}
649648
catch (Exception ex) {
650649
throw new IllegalStateException("Unable to read value from repeating annotation container "
651-
+ this.containerAnnotationType.getName(), ex);
650+
+ this.containerAnnotationType.getName(), ex);
652651
}
653652
}
654653

0 commit comments

Comments
 (0)