From 29d98285bea8be459d0bdcaad655c84338c3d0e5 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 16 Mar 2022 17:08:57 +0100 Subject: [PATCH] Add warning to "enclosing classes" search strategy for MergedAnnotations This commit adds a warning to the Javadoc for the TYPE_HIERARCHY_AND_ENCLOSING_CLASSES search strategy in MergedAnnotations with regard to the scope of the search algorithm. See gh-28079 --- .../core/annotation/MergedAnnotations.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 ef25638c01ff..81822f690ff2 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 @@ -483,12 +483,18 @@ enum SearchStrategy { *

This strategy is similar to {@link #TYPE_HIERARCHY} except that * {@linkplain Class#getEnclosingClass() enclosing classes} are also * searched. - *

Superclass annotations do not need to be meta-annotated with - * {@link Inherited @Inherited}. + *

Superclass and enclosing class annotations do not need to be + * meta-annotated with {@link Inherited @Inherited}. *

When searching a {@link Method} source, this strategy is identical * to {@link #TYPE_HIERARCHY}. + *

WARNING: This strategy searches recursively for + * annotations on the enclosing class for any source type, regardless + * whether the source type is an inner class, a {@code static} + * nested class, or a nested interface. Thus, it may find more annotations + * than you would expect. */ TYPE_HIERARCHY_AND_ENCLOSING_CLASSES + } }