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
This commit is contained in:
Juergen Hoeller
2012-09-25 12:49:38 +02:00
parent e0bec678da
commit 7fc16298e6

View File

@@ -69,7 +69,7 @@ public class InjectionMetadata {
}
public void checkConfigMembers(RootBeanDefinition beanDefinition) {
synchronized(this.injectedElements) {
synchronized (this.injectedElements) {
for (Iterator<InjectedElement> 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;
}
/**