Skip to content

UrlBasedViewResolvers should not override custom requestContextAttribute with null #23129

@sbrannen

Description

@sbrannen

Overview

org.springframework.web.servlet.view.UrlBasedViewResolver.buildView(String) and org.springframework.web.reactive.result.view.UrlBasedViewResolver.createView(String) both override the requestContextAttribute in the created View even if the requestContextAttribute in the UrlBasedViewResolver is null.

Consequently if a custom subclass of org.springframework.web.servlet.view.AbstractView or org.springframework.web.reactive.result.view.AbstractUrlBasedView configures the requestContextAttribute, it will be overwritten with null if the view is dynamically instantiated by a UrlBasedViewResolver. On the other hand, the custom configured requestContextAttribute will remain in tact if the view is used outside of a UrlBasedViewResolver, and this subtle difference can lead to unexpected results.

If the user explicitly configures the requestContextAttribute for a UrlBasedViewResolver, the user is probably (hopefully) aware of the effect. However, if the user does not explicitly configure the requestContextAttribute for a UrlBasedViewResolver we should not overwrite any custom configuration with null.

Deliverables

  • Only propagate a non-null requestContextAttribute to a dynamically instantiated View in UrlBasedViewResolver in spring-webmvc.
  • Only propagate a non-null requestContextAttribute to a dynamically instantiated View in UrlBasedViewResolver in spring-webflux.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions