Skip to content

Commit eef9bc8

Browse files
committed
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
1 parent 4690f74 commit eef9bc8

File tree

1 file changed

+4
-4
lines changed
  • spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker

1 file changed

+4
-4
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,17 @@ public boolean checkResourceExists(Locale locale) throws Exception {
219219
* @see org.springframework.web.reactive.result.view.AbstractView#getModelAttributes(Map, ServerWebExchange)
220220
*/
221221
@Override
222-
protected Mono<Map<String, Object>> getModelAttributes(Map<String, ?> model,
223-
ServerWebExchange exchange) {
222+
protected Mono<Map<String, Object>> getModelAttributes(
223+
@Nullable Map<String, ?> model, ServerWebExchange exchange) {
224224

225225
if (this.exposeSpringMacroHelpers) {
226-
if (model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
226+
if (model != null && model.containsKey(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)) {
227227
throw new IllegalStateException(
228228
"Cannot expose bind macro helper '" + SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE +
229229
"' because of an existing model object of the same name");
230230
}
231231
// Make a defensive copy of the model.
232-
Map<String, Object> attributes = new HashMap<>(model);
232+
Map<String, Object> attributes = (model != null ? new HashMap<>(model) : new HashMap<>());
233233
// Expose RequestContext instance for Spring macros.
234234
attributes.put(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, new RequestContext(
235235
exchange, attributes, obtainApplicationContext(), getRequestDataValueProcessor()));

0 commit comments

Comments
 (0)