Ignore null attributes in AbstractView

Consistent with ConcurrentModel and also with treatment of empty values
from async attributes.

Closes gh-23038
This commit is contained in:
Rossen Stoyanchev 2019-06-07 16:25:47 -04:00
parent 9f8148419f
commit 9ce5a18d96
1 changed files with 11 additions and 3 deletions

View File

@ -215,11 +215,19 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo
protected Mono<Map<String, Object>> getModelAttributes(
@Nullable Map<String, ?> model, ServerWebExchange exchange) {
int size = (model != null ? model.size() : 0);
Map<String, Object> attributes = new ConcurrentHashMap<>(size);
Map<String, Object> attributes;
if (model != null) {
attributes.putAll(model);
attributes = new ConcurrentHashMap<>(model.size());
for (Map.Entry<String, ?> entry : model.entrySet()) {
if (entry.getValue() != null) {
attributes.put(entry.getKey(), entry.getValue());
}
}
}
else {
attributes = new ConcurrentHashMap<>(0);
}
//noinspection deprecation
return resolveAsyncAttributes(attributes)
.then(resolveAsyncAttributes(attributes, exchange))