From ab4a50f31b3caba42834218fb6263cc91b455fa0 Mon Sep 17 00:00:00 2001 From: yilianhuaixiao <85142297@qq.com> Date: Mon, 20 Jul 2020 17:30:25 +0800 Subject: [PATCH 1/3] fixed bugs --- .../core/annotation/AnnotationsScanner.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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..5291411ad6ff 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 @@ -146,13 +146,15 @@ private static R processClassInheritedAnnotations(C context, Class sou Class root = source; while (source != null && source != Object.class && remaining > 0 && !hasPlainJavaAnnotationsOnly(source)) { + if (isFiltered(source, context, classFilter)) { + source = source.getSuperclass(); + aggregateIndex++; + continue; + } R result = processor.doWithAggregate(context, aggregateIndex); if (result != null) { return result; } - if (isFiltered(source, context, classFilter)) { - continue; - } Annotation[] declaredAnnotations = getDeclaredAnnotations(context, source, classFilter, true); if (relevant == null && declaredAnnotations.length > 0) { From a2a569c2aae63ed41b17e625beea341e837a2ded Mon Sep 17 00:00:00 2001 From: yilianhuaixiao <85142297@qq.com> Date: Tue, 21 Jul 2020 09:02:25 +0800 Subject: [PATCH 2/3] add testcase to check the bug#25429 --- .../core/annotation/AnnotationsScannerTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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"); From e894dbb7a34073408962f7b92899003a60a1e132 Mon Sep 17 00:00:00 2001 From: yilianhuaixiao <85142297@qq.com> Date: Tue, 21 Jul 2020 14:22:26 +0800 Subject: [PATCH 3/3] filter after doWithAggregate --- .../core/annotation/AnnotationsScanner.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 5291411ad6ff..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 @@ -146,15 +146,15 @@ private static R processClassInheritedAnnotations(C context, Class sou Class root = source; while (source != null && source != Object.class && remaining > 0 && !hasPlainJavaAnnotationsOnly(source)) { + R result = processor.doWithAggregate(context, aggregateIndex); + if (result != null) { + return result; + } if (isFiltered(source, context, classFilter)) { source = source.getSuperclass(); aggregateIndex++; continue; } - R result = processor.doWithAggregate(context, aggregateIndex); - if (result != null) { - return result; - } Annotation[] declaredAnnotations = getDeclaredAnnotations(context, source, classFilter, true); if (relevant == null && declaredAnnotations.length > 0) {