Skip to content

Commit d15abfd

Browse files
committed
Revert support for concurrent BeanPostProcessor registration in 4.3.x
Issue: SPR-17286
1 parent ebe3c27 commit d15abfd

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import java.util.Iterator;
3131
import java.util.LinkedHashMap;
3232
import java.util.LinkedHashSet;
33+
import java.util.LinkedList;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Set;
3637
import java.util.concurrent.ConcurrentHashMap;
37-
import java.util.concurrent.CopyOnWriteArrayList;
3838

3939
import org.springframework.beans.BeanUtils;
4040
import org.springframework.beans.BeanWrapper;
@@ -142,16 +142,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
142142
private TypeConverter typeConverter;
143143

144144
/** String resolvers to apply e.g. to annotation attribute values */
145-
private final List<StringValueResolver> embeddedValueResolvers = new CopyOnWriteArrayList<StringValueResolver>();
145+
private final List<StringValueResolver> embeddedValueResolvers = new LinkedList<StringValueResolver>();
146146

147147
/** BeanPostProcessors to apply in createBean */
148-
private volatile List<BeanPostProcessor> beanPostProcessors = new ArrayList<BeanPostProcessor>();
148+
private final List<BeanPostProcessor> beanPostProcessors = new ArrayList<BeanPostProcessor>();
149149

150150
/** Indicates whether any InstantiationAwareBeanPostProcessors have been registered */
151-
private volatile boolean hasInstantiationAwareBeanPostProcessors;
151+
private boolean hasInstantiationAwareBeanPostProcessors;
152152

153153
/** Indicates whether any DestructionAwareBeanPostProcessors have been registered */
154-
private volatile boolean hasDestructionAwareBeanPostProcessors;
154+
private boolean hasDestructionAwareBeanPostProcessors;
155155

156156
/** Map from scope identifier String to corresponding Scope */
157157
private final Map<String, Scope> scopes = new LinkedHashMap<String, Scope>(8);
@@ -845,22 +845,14 @@ public String resolveEmbeddedValue(String value) {
845845
@Override
846846
public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
847847
Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null");
848-
// Local copy set into volatile field, as an alternative to CopyOnWriteArrayList
849-
// (which doesn't support Iterator.remove for our getBeanPostProcessors result List)
850-
List<BeanPostProcessor> beanPostProcessors = new ArrayList<BeanPostProcessor>();
851-
beanPostProcessors.addAll(this.beanPostProcessors);
852-
// Remove from old position, if any
853-
beanPostProcessors.remove(beanPostProcessor);
854-
// Track whether it is instantiation/destruction aware
848+
this.beanPostProcessors.remove(beanPostProcessor);
849+
this.beanPostProcessors.add(beanPostProcessor);
855850
if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor) {
856851
this.hasInstantiationAwareBeanPostProcessors = true;
857852
}
858853
if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor) {
859854
this.hasDestructionAwareBeanPostProcessors = true;
860855
}
861-
// Add to end of list
862-
beanPostProcessors.add(beanPostProcessor);
863-
this.beanPostProcessors = beanPostProcessors;
864856
}
865857

866858
@Override

0 commit comments

Comments
 (0)