diff --git a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java index 77e7651938..4f52ecdf82 100644 --- a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java @@ -65,6 +65,23 @@ public class ConcurrentModel extends ConcurrentHashMap 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 map) { + for (Map.Entry 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 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; } diff --git a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java index caf52d03eb..6d093e5046 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java @@ -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 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;