From 88560fd910f9d1ca121340a86d6449b5151f0fc0 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 2 Jul 2010 16:08:25 +0000 Subject: [PATCH] SPR-7343: StandardEvaluationContext not threadsafe in its lazy initialization --- .../support/StandardEvaluationContext.java | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index 087fbabce2c..3a73fed4106 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -115,12 +115,6 @@ public class StandardEvaluationContext implements EvaluationContext { this.constructorResolvers = constructorResolvers; } - private void ensureConstructorResolversInitialized() { - if (this.constructorResolvers == null) { - this.constructorResolvers = new ArrayList(); - this.constructorResolvers.add(new ReflectiveConstructorResolver()); - } - } public void addMethodResolver(MethodResolver resolver) { ensureMethodResolversInitialized(); @@ -149,12 +143,6 @@ public class StandardEvaluationContext implements EvaluationContext { this.methodResolvers = methodResolvers; } - private void ensureMethodResolversInitialized() { - if (this.methodResolvers == null) { - this.methodResolvers = new ArrayList(); - this.methodResolvers.add(reflectiveMethodResolver=new ReflectiveMethodResolver()); - } - } public void addPropertyAccessor(PropertyAccessor accessor) { ensurePropertyAccessorsInitialized(); @@ -174,12 +162,6 @@ public class StandardEvaluationContext implements EvaluationContext { this.propertyAccessors = propertyAccessors; } - private void ensurePropertyAccessorsInitialized() { - if (this.propertyAccessors == null) { - this.propertyAccessors = new ArrayList(); - this.propertyAccessors.add(new ReflectivePropertyAccessor()); - } - } public void setTypeLocator(TypeLocator typeLocator) { Assert.notNull(typeLocator, "TypeLocator must not be null"); @@ -252,4 +234,46 @@ public class StandardEvaluationContext implements EvaluationContext { reflectiveMethodResolver.registerMethodFilter(type,filter); } + private void ensurePropertyAccessorsInitialized() { + if (this.propertyAccessors == null) { + initializePropertyAccessors(); + } + } + + private synchronized void initializePropertyAccessors() { + if (this.propertyAccessors == null) { + List defaultAccessors = new ArrayList(); + defaultAccessors.add(new ReflectivePropertyAccessor()); + this.propertyAccessors = defaultAccessors; + } + } + + private void ensureMethodResolversInitialized() { + if (this.methodResolvers == null) { + initializeMethodResolvers(); + } + } + + private synchronized void initializeMethodResolvers() { + if (this.methodResolvers == null) { + List defaultResolvers = new ArrayList(); + 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 defaultResolvers = new ArrayList(); + defaultResolvers.add(new ReflectiveConstructorResolver()); + this.constructorResolvers = defaultResolvers; + } + } + }