From 16ed7e2a19c074b26a99acc43fddb373db752fb7 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 10 Dec 2019 22:08:26 +0100 Subject: [PATCH] Only load enclosing class for TYPE_HIERARCHY_AND_ENCLOSING_CLASSES strategy Prior to this commit, the enclosing class was always eagerly loaded even if the annotation search strategy was not explicitly TYPE_HIERARCHY_AND_ENCLOSING_CLASSES. See gh-24136 --- .../core/annotation/AnnotationsScanner.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 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 de132349369..c41a67b73df 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 @@ -230,12 +230,14 @@ abstract class AnnotationsScanner { return superclassResult; } } - Class enclosingClass = source.getEnclosingClass(); - if (includeEnclosing && enclosingClass != null) { - R enclosingResult = processClassHierarchy(context, aggregateIndex, + if (includeEnclosing) { + Class enclosingClass = source.getEnclosingClass(); + if (enclosingClass != null) { + R enclosingResult = processClassHierarchy(context, aggregateIndex, enclosingClass, processor, classFilter, includeInterfaces, true); - if (enclosingResult != null) { - return enclosingResult; + if (enclosingResult != null) { + return enclosingResult; + } } } return null;