ConcurrentModel.addAttribute(String, Object) ignores null value

Issue: SPR-17141
This commit is contained in:
Juergen Hoeller
2018-08-07 20:35:34 +02:00
parent a4c750e94c
commit 34ddb88851
2 changed files with 28 additions and 28 deletions

View File

@@ -68,13 +68,17 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
/**
* Add the supplied attribute under the supplied name.
* @param attributeName the name of the model attribute (never {@code null})
* @param attributeValue the model attribute value (never {@code null} for {@code ConcurrentModel},
* with the {@code Nullable} declaration inherited from {@link Model#addAttribute(String, Object)})
* @param attributeValue the model attribute value (ignored if {@code null},
* just removing an existing entry if any)
*/
public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue) {
Assert.notNull(attributeName, "Model attribute name must not be null");
Assert.notNull(attributeValue, "ConcurrentModel does not support null attribute value");
put(attributeName, attributeValue);
if (attributeValue != null) {
put(attributeName, attributeValue);
}
else {
remove(attributeName);
}
return this;
}