From d3a5aefdff3e1ee1871ee20c175877594dd53a4c Mon Sep 17 00:00:00 2001 From: Seonghun Jeong <119427233+zzoe2346@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:16:34 +0900 Subject: [PATCH] Improve handling of `mainThreadPrefix` and remove redundant null check (#34746) --- .../beans/factory/support/DefaultListableBeanFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 2d3ef536e8..979a7d1880 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1048,7 +1048,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override protected @Nullable Boolean isCurrentThreadAllowedToHoldSingletonLock() { String mainThreadPrefix = this.mainThreadPrefix; - if (this.mainThreadPrefix != null) { + if (mainThreadPrefix != null) { // We only differentiate in the preInstantiateSingletons phase. PreInstantiation preInstantiation = this.preInstantiationThread.get(); @@ -1069,7 +1069,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } else if (this.strictLocking == null) { // No explicit locking configuration -> infer appropriate locking. - if (mainThreadPrefix != null && !getThreadNamePrefix().equals(mainThreadPrefix)) { + if (!getThreadNamePrefix().equals(mainThreadPrefix)) { // An unmanaged thread (assumed to be application-internal) with lenient locking, // and not part of the same thread pool that provided the main bootstrap thread // (excluding scenarios where we are hit by multiple external bootstrap threads).