From 7fc16298e68c58ab918cb331462658e99216ad2b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 25 Sep 2012 12:49:38 +0200 Subject: [PATCH] Fixed potential race condition in concurrent calling of autowired methods on a prototype bean Autowired methods might have been skipped on subsequent creation of further bean instances due to the 'skip' flag set to false outside of the synchronized block, with another thread entering the block and setting the flag to true in the meantime. Issue: SPR-9806 --- .../factory/annotation/InjectionMetadata.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index 88d6c417a1..c7fa84a72a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -69,7 +69,7 @@ public class InjectionMetadata { } public void checkConfigMembers(RootBeanDefinition beanDefinition) { - synchronized(this.injectedElements) { + synchronized (this.injectedElements) { for (Iterator it = this.injectedElements.iterator(); it.hasNext();) { Member member = it.next().getMember(); if (!beanDefinition.isExternallyManagedConfigMember(member)) { @@ -175,26 +175,30 @@ public class InjectionMetadata { * affected property as processed for other processors to ignore it. */ protected boolean checkPropertySkipping(PropertyValues pvs) { - if (this.skip == null) { - if (pvs != null) { - synchronized (pvs) { - if (this.skip == null) { - if (this.pd != null) { - if (pvs.contains(this.pd.getName())) { - // Explicit value provided as part of the bean definition. - this.skip = true; - return true; - } - else if (pvs instanceof MutablePropertyValues) { - ((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName()); - } - } - } + if (this.skip != null) { + return this.skip; + } + if (pvs == null) { + this.skip = false; + return false; + } + synchronized (pvs) { + if (this.skip != null) { + return this.skip; + } + if (this.pd != null) { + if (pvs.contains(this.pd.getName())) { + // Explicit value provided as part of the bean definition. + this.skip = true; + return true; + } + else if (pvs instanceof MutablePropertyValues) { + ((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName()); } } this.skip = false; + return false; } - return this.skip; } /**