From c2d0d292bd5d2419b898de89248638abb57e33cf Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:28:19 +0100 Subject: [PATCH] Re-resolve ContextLoader in logWarningForIgnoredDefaultConfig() Ideally, we should be able to reuse the ContextLoader that was resolved in buildDefaultMergedContextConfiguration(); however, since we have been informed that some implementations of resolveContextLoader() mutate the state of the supplied ContextConfigurationAttributes to detect default configuration classes, we need to invoke resolveContextLoader() on the completeDefaultConfigAttributesList as well in order not to break custom TestContextBootstrappers that exhibit such side effects. Closes gh-36390 --- .../support/AbstractTestContextBootstrapper.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 549a33ac2d6..90036bafa91 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -277,7 +277,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot } MergedContextConfiguration mergedConfig = buildMergedContextConfiguration( testClass, defaultConfigAttributesList, contextLoader, null, cacheAwareContextLoaderDelegate, false); - logWarningForIgnoredDefaultConfig(mergedConfig, contextLoader, cacheAwareContextLoaderDelegate); + logWarningForIgnoredDefaultConfig(mergedConfig, cacheAwareContextLoaderDelegate); return mergedConfig; } @@ -288,12 +288,20 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * being ignored. */ private void logWarningForIgnoredDefaultConfig(MergedContextConfiguration mergedConfig, - ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { if (logger.isWarnEnabled()) { Class testClass = mergedConfig.getTestClass(); List completeDefaultConfigAttributesList = ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass); + // Ideally, we should be able to reuse the ContextLoader that was resolved + // in buildDefaultMergedContextConfiguration(); however, since we have been + // informed that some implementations of resolveContextLoader() mutate the + // state of the supplied ContextConfigurationAttributes to detect default + // configuration classes, we need to invoke resolveContextLoader() on the + // completeDefaultConfigAttributesList as well in order not to break such + // custom TestContextBootstrappers. + ContextLoader contextLoader = resolveContextLoader(testClass, completeDefaultConfigAttributesList); MergedContextConfiguration completeMergedConfig = buildMergedContextConfiguration( testClass, completeDefaultConfigAttributesList, contextLoader, null, cacheAwareContextLoaderDelegate, false);