Browse Source

applied synchronization in order to avoid race condition in skipping check (SPR-7635, SPR-7642)

pull/1234/head
Juergen Hoeller 14 years ago
parent
commit
7893b3ebf6
  1. 9
      org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  2. 29
      org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

9
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -468,7 +468,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @@ -468,7 +468,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
value = resolvedCachedArgument(beanName, this.cachedFieldValue);
}
else {
synchronized (this) {
synchronized (pvs) {
if (!this.cached) {
Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
TypeConverter typeConverter = beanFactory.getTypeConverter();
@ -527,10 +527,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @@ -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 @@ -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];

29
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

@ -147,10 +147,7 @@ public class InjectionMetadata { @@ -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 { @@ -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;
}
/**

Loading…
Cancel
Save