Browse Source

StandardEvaluationContext supports concurrent variable modification

Issue: SPR-17448

(cherry picked from commit 59fa647e2d)
pull/2028/head
Juergen Hoeller 7 years ago
parent
commit
591e7f1f72
  1. 17
      spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java

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

@ -18,9 +18,9 @@ package org.springframework.expression.spel.support;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.BeanResolver; import org.springframework.expression.BeanResolver;
@ -88,7 +88,7 @@ public class StandardEvaluationContext implements EvaluationContext {
private OperatorOverloader operatorOverloader = new StandardOperatorOverloader(); private OperatorOverloader operatorOverloader = new StandardOperatorOverloader();
private final Map<String, Object> variables = new HashMap<>(); private final Map<String, Object> variables = new ConcurrentHashMap<>();
/** /**
@ -203,7 +203,7 @@ public class StandardEvaluationContext implements EvaluationContext {
@Override @Override
public TypeConverter getTypeConverter() { public TypeConverter getTypeConverter() {
if (this.typeConverter == null) { if (this.typeConverter == null) {
this.typeConverter = new StandardTypeConverter(); this.typeConverter = new StandardTypeConverter();
} }
return this.typeConverter; return this.typeConverter;
} }
@ -230,11 +230,16 @@ public class StandardEvaluationContext implements EvaluationContext {
@Override @Override
public void setVariable(String name, @Nullable Object value) { public void setVariable(String name, @Nullable Object value) {
this.variables.put(name, value); if (value != null) {
this.variables.put(name, value);
}
else {
this.variables.remove(name);
}
} }
public void setVariables(Map<String,Object> variables) { public void setVariables(Map<String, Object> variables) {
this.variables.putAll(variables); variables.forEach(this::setVariable);
} }
public void registerFunction(String name, Method method) { public void registerFunction(String name, Method method) {

Loading…
Cancel
Save