From ac5b1bcfabf30273e69359ba4ead29b4704eaa89 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Oct 2010 22:56:38 +0000 Subject: [PATCH] fixed Autowired/CommonAnnotationBeanPostProcessor to prevent race condition in skipping check (SPR-7635, SPR-7642) --- .../AutowiredAnnotationBeanPostProcessor.java | 16 ++++------------ .../factory/annotation/InjectionMetadata.java | 4 ++-- 2 files changed, 6 insertions(+), 14 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 52cf15866a8..bdfdde8082d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; -import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValues; import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanCreationException; @@ -528,11 +527,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @Override protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable { - if (this.skip == null && this.pd != null && pvs != null && pvs.contains(this.pd.getName())) { - // Explicit value provided as part of the bean definition. - this.skip = Boolean.TRUE; + if (this.skip == null) { + this.skip = checkPropertySkipping(pvs); } - if (this.skip != null && this.skip) { + if (this.skip) { return; } Method method = (Method) this.member; @@ -590,12 +588,6 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } } } - if (this.skip == null) { - if (this.pd != null && pvs instanceof MutablePropertyValues) { - ((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName()); - } - this.skip = Boolean.FALSE; - } if (arguments != null) { ReflectionUtils.makeAccessible(method); method.invoke(bean, arguments); 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 737e3b75859..7f46e67c4e3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,7 +171,7 @@ public class InjectionMetadata { */ protected boolean checkPropertySkipping(PropertyValues pvs) { if (this.pd != null && pvs != null) { - if (pvs.contains(this.pd.getName())) { + if (pvs.getPropertyValue(this.pd.getName()) != null) { // Explicit value provided as part of the bean definition. return true; }