Avoid NPE in FreeMarkerView.getModelAttributes() in spring-webflux
This commit declares the model method parameter as @Nullable and adds defensive guards against a null model argument. Closes gh-23105
This commit is contained in:
parent
4690f745ce
commit
eef9bc899f
|
|
@ -219,17 +219,17 @@ public class FreeMarkerView extends AbstractUrlBasedView {
|
||||||
* @see org.springframework.web.reactive.result.view.AbstractView#getModelAttributes(Map, ServerWebExchange)
|
* @see org.springframework.web.reactive.result.view.AbstractView#getModelAttributes(Map, ServerWebExchange)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Mono<Map<String, Object>> getModelAttributes(Map<String, ?> model,
|
protected Mono<Map<String, Object>> getModelAttributes(
|
||||||
ServerWebExchange exchange) {
|
@Nullable Map<String, ?> model, ServerWebExchange exchange) {
|
||||||
|
|
||||||
if (this.exposeSpringMacroHelpers) {
|
if (this.exposeSpringMacroHelpers) {
|
||||||
if (model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
|
if (model != null && model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Cannot expose bind macro helper '" + SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE +
|
"Cannot expose bind macro helper '" + SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE +
|
||||||
"' because of an existing model object of the same name");
|
"' because of an existing model object of the same name");
|
||||||
}
|
}
|
||||||
// Make a defensive copy of the model.
|
// Make a defensive copy of the model.
|
||||||
Map<String, Object> attributes = new HashMap<>(model);
|
Map<String, Object> attributes = (model != null ? new HashMap<>(model) : new HashMap<>());
|
||||||
// Expose RequestContext instance for Spring macros.
|
// Expose RequestContext instance for Spring macros.
|
||||||
attributes.put(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, new RequestContext(
|
attributes.put(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, new RequestContext(
|
||||||
exchange, attributes, obtainApplicationContext(), getRequestDataValueProcessor()));
|
exchange, attributes, obtainApplicationContext(), getRequestDataValueProcessor()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue