diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java index 67ccd303244f..795c7a036c0e 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java @@ -151,6 +151,8 @@ private static R processClassInheritedAnnotations(C context, Class sou return result; } if (isFiltered(source, context, classFilter)) { + source = source.getSuperclass(); + aggregateIndex++; continue; } Annotation[] declaredAnnotations = diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java index 635452343b23..80a621930ccc 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java @@ -499,6 +499,22 @@ public String finish(String result) { assertThat(result).isEqualTo("OK"); } + @Test + void scanWithFilteredAll() { + List 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");