Skip to content

Commit

Permalink
Avoid infinite loop in AnnotationScanner
Browse files Browse the repository at this point in the history
Prior to this commit, scanning for annotations resulted in an infinite
loop when using the INHERITED_ANNOTATIONS search strategy and a class
filter that filters out visited classes.

This commit avoids an infinite loop in AnnotationsScanner's
processClassInheritedAnnotations(...) method by skipping the current
level of the class hierarchy when the current source class has been
filtered out.

Closes gh-25429
  • Loading branch information
yilianhuaixiao authored and sbrannen committed Jul 25, 2020
1 parent 335c3d5 commit 650cbee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -151,6 +151,8 @@ private static <C, R> R processClassInheritedAnnotations(C context, Class<?> sou
return result;
}
if (isFiltered(source, context, classFilter)) {
source = source.getSuperclass();
aggregateIndex++;
continue;
}
Annotation[] declaredAnnotations =
Expand Down
Expand Up @@ -499,6 +499,22 @@ public String finish(String result) {
assertThat(result).isEqualTo("OK");
}

@Test
void scanWithFilteredAll() {
List<Integer> indexes = new ArrayList<>();
String result = AnnotationsScanner.scan(this, WithSingleSuperclass.class,
SearchStrategy.INHERITED_ANNOTATIONS,
(context, aggregateIndex, source, annotations) -> {
indexes.add(aggregateIndex);
return "";
},
(context,cls)->{
return true;
}
);
assertThat(result).isNull();
}


private Method methodFrom(Class<?> type) {
return ReflectionUtils.findMethod(type, "method");
Expand Down

0 comments on commit 650cbee

Please sign in to comment.