Skip to content

Commit b48d72c

Browse files
committedFeb 18, 2025·
Apply fallback in case of initial SmartClassLoader mismatch as well
See gh-34423 (cherry picked from commit 6786e1c)
1 parent 4862819 commit b48d72c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed
 

‎spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ public Class<?> enhance(Class<?> configClass, @Nullable ClassLoader classLoader)
112112

113113
try {
114114
// Use original ClassLoader if config class not locally loaded in overriding class loader
115-
if (classLoader instanceof SmartClassLoader smartClassLoader &&
116-
classLoader != configClass.getClassLoader()) {
115+
boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader());
116+
if (classLoaderMismatch && classLoader instanceof SmartClassLoader smartClassLoader) {
117117
classLoader = smartClassLoader.getOriginalClassLoader();
118118
}
119119
Enhancer enhancer = newEnhancer(configClass, classLoader);
120-
boolean classLoaderMismatch = (classLoader != null && classLoader != configClass.getClassLoader());
121120
Class<?> enhancedClass = createClass(enhancer, classLoaderMismatch);
122121
if (logger.isTraceEnabled()) {
123122
logger.trace(String.format("Successfully enhanced %s; enhanced class name is: %s",
@@ -188,8 +187,7 @@ private Class<?> createClass(Enhancer enhancer, boolean fallback) {
188187
/**
189188
* Marker interface to be implemented by all @Configuration CGLIB subclasses.
190189
* Facilitates idempotent behavior for {@link ConfigurationClassEnhancer#enhance}
191-
* through checking to see if candidate classes are already assignable to it, e.g.
192-
* have already been enhanced.
190+
* through checking to see if candidate classes are already assignable to it.
193191
* <p>Also extends {@link BeanFactoryAware}, as all enhanced {@code @Configuration}
194192
* classes require access to the {@link BeanFactory} that created them.
195193
* <p>Note that this interface is intended for framework-internal use only, however

0 commit comments

Comments
 (0)
Please sign in to comment.