Skip to content

Commit 591e7f1

Browse files
committed
StandardEvaluationContext supports concurrent variable modification
Issue: SPR-17448 (cherry picked from commit 59fa647)
1 parent c834790 commit 591e7f1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import java.lang.reflect.Method;
2020
import java.util.ArrayList;
21-
import java.util.HashMap;
2221
import java.util.List;
2322
import java.util.Map;
23+
import java.util.concurrent.ConcurrentHashMap;
2424

2525
import org.springframework.core.convert.TypeDescriptor;
2626
import org.springframework.expression.BeanResolver;
@@ -88,7 +88,7 @@ public class StandardEvaluationContext implements EvaluationContext {
8888

8989
private OperatorOverloader operatorOverloader = new StandardOperatorOverloader();
9090

91-
private final Map<String, Object> variables = new HashMap<>();
91+
private final Map<String, Object> variables = new ConcurrentHashMap<>();
9292

9393

9494
/**
@@ -203,7 +203,7 @@ public void setTypeConverter(TypeConverter typeConverter) {
203203
@Override
204204
public TypeConverter getTypeConverter() {
205205
if (this.typeConverter == null) {
206-
this.typeConverter = new StandardTypeConverter();
206+
this.typeConverter = new StandardTypeConverter();
207207
}
208208
return this.typeConverter;
209209
}
@@ -230,11 +230,16 @@ public OperatorOverloader getOperatorOverloader() {
230230

231231
@Override
232232
public void setVariable(String name, @Nullable Object value) {
233-
this.variables.put(name, value);
233+
if (value != null) {
234+
this.variables.put(name, value);
235+
}
236+
else {
237+
this.variables.remove(name);
238+
}
234239
}
235240

236-
public void setVariables(Map<String,Object> variables) {
237-
this.variables.putAll(variables);
241+
public void setVariables(Map<String, Object> variables) {
242+
variables.forEach(this::setVariable);
238243
}
239244

240245
public void registerFunction(String name, Method method) {

0 commit comments

Comments
 (0)