Skip to content

Commit ac5b1bc

Browse files
committed
fixed Autowired/CommonAnnotationBeanPostProcessor to prevent race condition in skipping check (SPR-7635, SPR-7642)
1 parent c5c1d70 commit ac5b1bc

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,6 @@
3838

3939
import org.springframework.beans.BeanUtils;
4040
import org.springframework.beans.BeansException;
41-
import org.springframework.beans.MutablePropertyValues;
4241
import org.springframework.beans.PropertyValues;
4342
import org.springframework.beans.TypeConverter;
4443
import org.springframework.beans.factory.BeanCreationException;
@@ -528,11 +527,10 @@ public AutowiredMethodElement(Method method, boolean required, PropertyDescripto
528527

529528
@Override
530529
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
531-
if (this.skip == null && this.pd != null && pvs != null && pvs.contains(this.pd.getName())) {
532-
// Explicit value provided as part of the bean definition.
533-
this.skip = Boolean.TRUE;
530+
if (this.skip == null) {
531+
this.skip = checkPropertySkipping(pvs);
534532
}
535-
if (this.skip != null && this.skip) {
533+
if (this.skip) {
536534
return;
537535
}
538536
Method method = (Method) this.member;
@@ -590,12 +588,6 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T
590588
}
591589
}
592590
}
593-
if (this.skip == null) {
594-
if (this.pd != null && pvs instanceof MutablePropertyValues) {
595-
((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
596-
}
597-
this.skip = Boolean.FALSE;
598-
}
599591
if (arguments != null) {
600592
ReflectionUtils.makeAccessible(method);
601593
method.invoke(bean, arguments);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -171,7 +171,7 @@ protected void inject(Object target, String requestingBeanName, PropertyValues p
171171
*/
172172
protected boolean checkPropertySkipping(PropertyValues pvs) {
173173
if (this.pd != null && pvs != null) {
174-
if (pvs.contains(this.pd.getName())) {
174+
if (pvs.getPropertyValue(this.pd.getName()) != null) {
175175
// Explicit value provided as part of the bean definition.
176176
return true;
177177
}

0 commit comments

Comments
 (0)