From 5689395678f57fe967a3b21ed7d9087cfec7b622 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 19 Feb 2022 16:51:00 +0100 Subject: [PATCH 1/2] Deprecate "enclosing classes" search strategy for MergedAnnotations The TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy for MergedAnnotations was originally introduced to support @Nested test classes in JUnit Jupiter (see #23378). However, while implementing #19930, we determined that the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy unfortunately could not be used since it does not allow the user to control when to recurse up the enclosing class hierarchy. For example, this search strategy will automatically search on enclosing classes for static nested classes as well as for inner classes, when the user probably only wants one such category of "enclosing class" to be searched. Consequently, TestContextAnnotationUtils was introduced in the Spring TestContext Framework to address the shortcomings of the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy. Since this search strategy is unlikely to be useful to general users, the team has decided to deprecate this search strategy in Spring Framework 5.3.x and remove it in 6.0. Closes gh-28079 --- .../springframework/core/annotation/AnnotationsScanner.java | 5 ++++- .../springframework/core/annotation/MergedAnnotations.java | 2 ++ .../core/annotation/AnnotationsScannerTests.java | 5 ++++- .../core/annotation/MergedAnnotationsTests.java | 2 ++ 4 files changed, 12 insertions(+), 2 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 626413838c..70efaeea41 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,6 +92,7 @@ abstract class AnnotationsScanner { } @Nullable + @SuppressWarnings("deprecation") private static R processClass(C context, Class source, SearchStrategy searchStrategy, AnnotationsProcessor processor) { @@ -235,6 +236,7 @@ abstract class AnnotationsScanner { } @Nullable + @SuppressWarnings("deprecation") private static R processMethod(C context, Method source, SearchStrategy searchStrategy, AnnotationsProcessor processor) { @@ -510,6 +512,7 @@ abstract class AnnotationsScanner { return (type.getName().startsWith("java.") || type == Ordered.class); } + @SuppressWarnings("deprecation") private static boolean isWithoutHierarchy(AnnotatedElement source, SearchStrategy searchStrategy) { if (source == Object.class) { return true; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java index 55dff9086f..28f7cf009a 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java @@ -482,7 +482,9 @@ public interface MergedAnnotations extends Iterable * need to be meta-annotated with {@link Inherited @Inherited}. When * searching a {@link Method} source, this strategy is identical to * {@link #TYPE_HIERARCHY}. + * @deprecated as of Spring Framework 5.3.17; to be removed in Spring Framework 6.0 */ + @Deprecated TYPE_HIERARCHY_AND_ENCLOSING_CLASSES } 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 83518d9b38..e848090b12 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -421,6 +421,7 @@ class AnnotationsScannerTests { } @Test + @SuppressWarnings("deprecation") void typeHierarchyWithEnclosedStrategyOnEnclosedStaticClassScansAnnotations() { Class source = AnnotationEnclosingClassSample.EnclosedStatic.EnclosedStaticStatic.class; assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES)) @@ -428,6 +429,7 @@ class AnnotationsScannerTests { } @Test + @SuppressWarnings("deprecation") void typeHierarchyWithEnclosedStrategyOnEnclosedInnerClassScansAnnotations() { Class source = AnnotationEnclosingClassSample.EnclosedInner.EnclosedInnerInner.class; assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES)) @@ -435,6 +437,7 @@ class AnnotationsScannerTests { } @Test + @SuppressWarnings("deprecation") void typeHierarchyWithEnclosedStrategyOnMethodHierarchyUsesTypeHierarchyScan() { Method source = methodFrom(WithHierarchy.class); assertThat(scan(source, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES)).containsExactly( diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 02ec8f0980..e175e6e030 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -712,6 +712,7 @@ class MergedAnnotationsTests { } @Test + @SuppressWarnings("deprecation") void streamTypeHierarchyAndEnclosingClassesFromNonAnnotatedInnerClassWithAnnotatedEnclosingClass() { Stream> classes = MergedAnnotations.from(AnnotatedClass.NonAnnotatedInnerClass.class, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES).stream().map(MergedAnnotation::getType); @@ -719,6 +720,7 @@ class MergedAnnotationsTests { } @Test + @SuppressWarnings("deprecation") void streamTypeHierarchyAndEnclosingClassesFromNonAnnotatedStaticNestedClassWithAnnotatedEnclosingClass() { Stream> classes = MergedAnnotations.from(AnnotatedClass.NonAnnotatedStaticNestedClass.class, SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES).stream().map(MergedAnnotation::getType); From 84b4cebb3913ddd4a803939fdc8dde1b0401ff35 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 19 Feb 2022 16:54:16 +0100 Subject: [PATCH 2/2] Fix (@)since tag in SpelMessage See gh-28043 --- .../java/org/springframework/expression/spel/SpelMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java index b8f5f92d05..9c08841158 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java @@ -258,7 +258,7 @@ public enum SpelMessage { FLAWED_PATTERN(Kind.ERROR, 1073, "Failed to efficiently evaluate pattern ''{0}'': consider redesigning it"), - /** @since 5.3.16 */ + /** @since 5.3.17 */ EXCEPTION_COMPILING_EXPRESSION(Kind.ERROR, 1074, "An exception occurred while compiling an expression");