From aeb77cf4e1506745db53b4514479368387e72786 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 28 Feb 2024 11:47:39 +0100 Subject: [PATCH] Restore correct threadWithLock check without isInfoEnabled() See gh-23501 --- .../support/DefaultSingletonBeanRegistry.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index 66c0bb4a8c52..8cd40e2aa8eb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -239,14 +239,16 @@ public Object getSingleton(String beanName, ObjectFactory singletonFactory) { } else { Thread threadWithLock = this.singletonCreationThread; - // Another thread is busy in a singleton factory callback, potentially blocked. - // Fallback as of 6.2: process given singleton bean outside of singleton lock. - // Thread-safe exposure is still guaranteed, there is just a risk of collisions - // when triggering creation of other beans as dependencies of the current bean. - if (threadWithLock != null && logger.isInfoEnabled()) { - logger.info("Creating singleton bean '" + beanName + "' in thread \"" + - Thread.currentThread().getName() + "\" while thread \"" + threadWithLock.getName() + - "\" holds singleton lock for other beans " + this.singletonsCurrentlyInCreation); + if (threadWithLock != null) { + // Another thread is busy in a singleton factory callback, potentially blocked. + // Fallback as of 6.2: process given singleton bean outside of singleton lock. + // Thread-safe exposure is still guaranteed, there is just a risk of collisions + // when triggering creation of other beans as dependencies of the current bean. + if (logger.isInfoEnabled()) { + logger.info("Creating singleton bean '" + beanName + "' in thread \"" + + Thread.currentThread().getName() + "\" while thread \"" + threadWithLock.getName() + + "\" holds singleton lock for other beans " + this.singletonsCurrentlyInCreation); + } } else { // Singleton lock currently held by some other registration method -> wait.