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

This commit is contained in:
Juergen Hoeller 2010-10-13 22:29:28 +00:00
parent 21d6883139
commit 7893b3ebf6
2 changed files with 20 additions and 18 deletions

View File

@ -468,7 +468,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
value = resolvedCachedArgument(beanName, this.cachedFieldValue); value = resolvedCachedArgument(beanName, this.cachedFieldValue);
} }
else { else {
synchronized (this) { synchronized (pvs) {
if (!this.cached) { if (!this.cached) {
Set<String> autowiredBeanNames = new LinkedHashSet<String>(1); Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
TypeConverter typeConverter = beanFactory.getTypeConverter(); TypeConverter typeConverter = beanFactory.getTypeConverter();
@ -527,10 +527,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@Override @Override
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
if (this.skip == null) { if (checkPropertySkipping(pvs)) {
this.skip = checkPropertySkipping(pvs);
}
if (this.skip) {
return; return;
} }
Method method = (Method) this.member; Method method = (Method) this.member;
@ -541,7 +538,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
arguments = resolveCachedArguments(beanName); arguments = resolveCachedArguments(beanName);
} }
else { else {
synchronized (this) { synchronized (pvs) {
if (!this.cached) { if (!this.cached) {
Class[] paramTypes = method.getParameterTypes(); Class[] paramTypes = method.getParameterTypes();
arguments = new Object[paramTypes.length]; arguments = new Object[paramTypes.length];

View File

@ -147,10 +147,7 @@ public class InjectionMetadata {
field.set(target, getResourceToInject(target, requestingBeanName)); field.set(target, getResourceToInject(target, requestingBeanName));
} }
else { else {
if (this.skip == null) { if (checkPropertySkipping(pvs)) {
this.skip = checkPropertySkipping(pvs);
}
if (this.skip) {
return; return;
} }
try { try {
@ -170,16 +167,24 @@ public class InjectionMetadata {
* affected property as processed for other processors to ignore it. * affected property as processed for other processors to ignore it.
*/ */
protected boolean checkPropertySkipping(PropertyValues pvs) { protected boolean checkPropertySkipping(PropertyValues pvs) {
if (this.pd != null && pvs != null) { if (this.skip == null) {
if (pvs.getPropertyValue(this.pd.getName()) != null) { synchronized (pvs) {
// Explicit value provided as part of the bean definition. if (this.skip == null) {
return true; if (this.pd != null && pvs != null) {
} if (pvs.contains(this.pd.getName())) {
else if (pvs instanceof MutablePropertyValues) { // Explicit value provided as part of the bean definition.
((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName()); this.skip = true;
return true;
}
else if (pvs instanceof MutablePropertyValues) {
((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
}
}
this.skip = false;
}
} }
} }
return false; return this.skip;
} }
/** /**