SPR-7343: StandardEvaluationContext not threadsafe in its lazy initialization

This commit is contained in:
Andy Clement 2010-07-02 16:08:25 +00:00
parent 6de707d8e0
commit 88560fd910
1 changed files with 42 additions and 18 deletions

View File

@ -115,12 +115,6 @@ public class StandardEvaluationContext implements EvaluationContext {
this.constructorResolvers = constructorResolvers; this.constructorResolvers = constructorResolvers;
} }
private void ensureConstructorResolversInitialized() {
if (this.constructorResolvers == null) {
this.constructorResolvers = new ArrayList<ConstructorResolver>();
this.constructorResolvers.add(new ReflectiveConstructorResolver());
}
}
public void addMethodResolver(MethodResolver resolver) { public void addMethodResolver(MethodResolver resolver) {
ensureMethodResolversInitialized(); ensureMethodResolversInitialized();
@ -149,12 +143,6 @@ public class StandardEvaluationContext implements EvaluationContext {
this.methodResolvers = methodResolvers; this.methodResolvers = methodResolvers;
} }
private void ensureMethodResolversInitialized() {
if (this.methodResolvers == null) {
this.methodResolvers = new ArrayList<MethodResolver>();
this.methodResolvers.add(reflectiveMethodResolver=new ReflectiveMethodResolver());
}
}
public void addPropertyAccessor(PropertyAccessor accessor) { public void addPropertyAccessor(PropertyAccessor accessor) {
ensurePropertyAccessorsInitialized(); ensurePropertyAccessorsInitialized();
@ -174,12 +162,6 @@ public class StandardEvaluationContext implements EvaluationContext {
this.propertyAccessors = propertyAccessors; this.propertyAccessors = propertyAccessors;
} }
private void ensurePropertyAccessorsInitialized() {
if (this.propertyAccessors == null) {
this.propertyAccessors = new ArrayList<PropertyAccessor>();
this.propertyAccessors.add(new ReflectivePropertyAccessor());
}
}
public void setTypeLocator(TypeLocator typeLocator) { public void setTypeLocator(TypeLocator typeLocator) {
Assert.notNull(typeLocator, "TypeLocator must not be null"); Assert.notNull(typeLocator, "TypeLocator must not be null");
@ -252,4 +234,46 @@ public class StandardEvaluationContext implements EvaluationContext {
reflectiveMethodResolver.registerMethodFilter(type,filter); reflectiveMethodResolver.registerMethodFilter(type,filter);
} }
private void ensurePropertyAccessorsInitialized() {
if (this.propertyAccessors == null) {
initializePropertyAccessors();
}
}
private synchronized void initializePropertyAccessors() {
if (this.propertyAccessors == null) {
List<PropertyAccessor> defaultAccessors = new ArrayList<PropertyAccessor>();
defaultAccessors.add(new ReflectivePropertyAccessor());
this.propertyAccessors = defaultAccessors;
}
}
private void ensureMethodResolversInitialized() {
if (this.methodResolvers == null) {
initializeMethodResolvers();
}
}
private synchronized void initializeMethodResolvers() {
if (this.methodResolvers == null) {
List<MethodResolver> defaultResolvers = new ArrayList<MethodResolver>();
defaultResolvers.add(reflectiveMethodResolver = new ReflectiveMethodResolver());
this.methodResolvers = defaultResolvers;
}
}
private void ensureConstructorResolversInitialized() {
if (this.constructorResolvers == null) {
initializeConstructorResolvers();
}
}
private synchronized void initializeConstructorResolvers() {
if (this.constructorResolvers == null) {
List<ConstructorResolver> defaultResolvers = new ArrayList<ConstructorResolver>();
defaultResolvers.add(new ReflectiveConstructorResolver());
this.constructorResolvers = defaultResolvers;
}
}
} }