Avoid early singleton inference outside of original creation thread

See gh-23501
This commit is contained in:
Juergen Hoeller
2024-02-19 17:44:30 +01:00
parent 902e5707a8
commit 4a02893c31
2 changed files with 17 additions and 4 deletions

View File

@@ -188,7 +188,10 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
singletonObject = this.earlySingletonObjects.get(beanName);
if (singletonObject == null && allowEarlyReference) {
this.singletonLock.lock();
if (!this.singletonLock.tryLock()) {
// Avoid early singleton inference outside of original creation thread
return null;
}
try {
// Consistent creation of early reference within full singleton lock
singletonObject = this.singletonObjects.get(beanName);