From 7893b3ebf68946a942e55d12ba828bfd044e4d00 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Oct 2010 22:29:28 +0000 Subject: [PATCH] applied synchronization in order to avoid race condition in skipping check (SPR-7635, SPR-7642) --- .../AutowiredAnnotationBeanPostProcessor.java | 9 ++---- .../factory/annotation/InjectionMetadata.java | 29 +++++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index bdfdde8082..9518e4eb41 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -468,7 +468,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean value = resolvedCachedArgument(beanName, this.cachedFieldValue); } else { - synchronized (this) { + synchronized (pvs) { if (!this.cached) { Set autowiredBeanNames = new LinkedHashSet(1); TypeConverter typeConverter = beanFactory.getTypeConverter(); @@ -527,10 +527,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @Override protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { - if (this.skip == null) { - this.skip = checkPropertySkipping(pvs); - } - if (this.skip) { + if (checkPropertySkipping(pvs)) { return; } Method method = (Method) this.member; @@ -541,7 +538,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean arguments = resolveCachedArguments(beanName); } else { - synchronized (this) { + synchronized (pvs) { if (!this.cached) { Class[] paramTypes = method.getParameterTypes(); arguments = new Object[paramTypes.length]; diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index 7f46e67c4e..ceffe5fc5a 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -147,10 +147,7 @@ public class InjectionMetadata { field.set(target, getResourceToInject(target, requestingBeanName)); } else { - if (this.skip == null) { - this.skip = checkPropertySkipping(pvs); - } - if (this.skip) { + if (checkPropertySkipping(pvs)) { return; } try { @@ -170,16 +167,24 @@ public class InjectionMetadata { * affected property as processed for other processors to ignore it. */ protected boolean checkPropertySkipping(PropertyValues pvs) { - if (this.pd != null && pvs != null) { - if (pvs.getPropertyValue(this.pd.getName()) != null) { - // Explicit value provided as part of the bean definition. - return true; - } - else if (pvs instanceof MutablePropertyValues) { - ((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName()); + if (this.skip == null) { + synchronized (pvs) { + if (this.skip == null) { + if (this.pd != null && pvs != 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; } /**