Skip to content

Commit b8b6367

Browse files
committed
ConcurrentModel ignores null value for put (also used by putAll)
Issue: SPR-17141
1 parent 7077af1 commit b8b6367

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public ConcurrentModel(Object attributeValue) {
6565
}
6666

6767

68+
@Override
69+
public Object put(String key, Object value) {
70+
if (value != null) {
71+
return super.put(key, value);
72+
}
73+
else {
74+
return remove(key);
75+
}
76+
}
77+
78+
@Override
79+
public void putAll(Map<? extends String, ?> map) {
80+
for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
81+
put(entry.getKey(), entry.getValue());
82+
}
83+
}
84+
6885
/**
6986
* Add the supplied attribute under the supplied name.
7087
* @param attributeName the name of the model attribute (never {@code null})
@@ -73,12 +90,7 @@ public ConcurrentModel(Object attributeValue) {
7390
*/
7491
public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue) {
7592
Assert.notNull(attributeName, "Model attribute name must not be null");
76-
if (attributeValue != null) {
77-
put(attributeName, attributeValue);
78-
}
79-
else {
80-
remove(attributeName);
81-
}
93+
put(attributeName, attributeValue);
8294
return this;
8395
}
8496

spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,12 +46,6 @@ public Object put(String key, Object value) {
4646
return super.put(key, value);
4747
}
4848

49-
@Override
50-
public void putAll(Map<? extends String, ?> map) {
51-
map.forEach(this::removeBindingResultIfNecessary);
52-
super.putAll(map);
53-
}
54-
5549
private void removeBindingResultIfNecessary(String key, Object value) {
5650
if (!key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
5751
String resultKey = BindingResult.MODEL_KEY_PREFIX + key;

0 commit comments

Comments
 (0)