Skip to content

Commit db63f7d

Browse files
committed
StandardEvaluationContext.setVariable leniently ignores null name
Issue: SPR-17565
1 parent 7a5f8e0 commit db63f7d

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,17 @@ public OperatorOverloader getOperatorOverloader() {
229229
}
230230

231231
@Override
232-
public void setVariable(String name, @Nullable Object value) {
233-
if (value != null) {
234-
this.variables.put(name, value);
235-
}
236-
else {
237-
this.variables.remove(name);
232+
public void setVariable(@Nullable String name, @Nullable Object value) {
233+
// For backwards compatibility, we ignore null names here...
234+
// And since ConcurrentHashMap cannot store null values, we simply take null
235+
// as a remove from the Map (with the same result from lookupVariable below).
236+
if (name != null) {
237+
if (value != null) {
238+
this.variables.put(name, value);
239+
}
240+
else {
241+
this.variables.remove(name);
242+
}
238243
}
239244
}
240245

0 commit comments

Comments
 (0)