From 71463fb3991a2b7e8e79cafa91a824c51f4fc73a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 31 May 2016 14:12:06 +0200 Subject: [PATCH] AbstractBeanFactory consistently guards add/remove operations against alreadyCreated Set Issue: SPR-14269 --- .../beans/factory/support/AbstractBeanFactory.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 2379675c81..62dfa38e42 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1504,10 +1504,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp protected void markBeanAsCreated(String beanName) { if (!this.alreadyCreated.contains(beanName)) { synchronized (this.mergedBeanDefinitions) { - if (this.alreadyCreated.add(beanName)) { + if (!this.alreadyCreated.contains(beanName)) { // Let the bean definition get re-merged now that we're actually creating // the bean... just in case some of its metadata changed in the meantime. clearMergedBeanDefinition(beanName); + this.alreadyCreated.add(beanName); } } } @@ -1518,7 +1519,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param beanName the name of the bean */ protected void cleanupAfterBeanCreationFailure(String beanName) { - this.alreadyCreated.remove(beanName); + synchronized (this.mergedBeanDefinitions) { + this.alreadyCreated.remove(beanName); + } } /**