ConcurrentModel ignores null value for put (also used by putAll)

Issue: SPR-17141
This commit is contained in:
Juergen Hoeller 2018-08-08 23:51:55 +02:00
parent 7077af14f1
commit b8b6367f9b
2 changed files with 19 additions and 13 deletions

View File

@ -65,6 +65,23 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
}
@Override
public Object put(String key, Object value) {
if (value != null) {
return super.put(key, value);
}
else {
return remove(key);
}
}
@Override
public void putAll(Map<? extends String, ?> map) {
for (Map.Entry<? extends String, ?> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
/**
* Add the supplied attribute under the supplied name.
* @param attributeName the name of the model attribute (never {@code null})
@ -73,12 +90,7 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
*/
public ConcurrentModel addAttribute(String attributeName, @Nullable Object attributeValue) {
Assert.notNull(attributeName, "Model attribute name must not be null");
if (attributeValue != null) {
put(attributeName, attributeValue);
}
else {
remove(attributeName);
}
put(attributeName, attributeValue);
return this;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,12 +46,6 @@ public class BindingAwareConcurrentModel extends ConcurrentModel {
return super.put(key, value);
}
@Override
public void putAll(Map<? extends String, ?> map) {
map.forEach(this::removeBindingResultIfNecessary);
super.putAll(map);
}
private void removeBindingResultIfNecessary(String key, Object value) {
if (!key.startsWith(BindingResult.MODEL_KEY_PREFIX)) {
String resultKey = BindingResult.MODEL_KEY_PREFIX + key;