spring-projects / spring-projects/spring-framework
WebFlux RequestContext.changeLocale() lacks Javadoc for rendering-scope limitation (MVC parity gap)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Problem
RequestContext.changeLocale(Locale) exists in both Spring MVC and Spring WebFlux with identical method names and signatures. In MVC, the method persists the locale change through the configured LocaleResolver. In WebFlux, it updates only the private field on the current RequestContext instance — the change is scoped to the current rendering cycle and silently discarded on the next request.
The asymmetry itself may be defensible given the reactive model. The MVC equivalent has explicit Javadoc linking @see LocaleResolver#setLocale and documenting persistence behavior. The WebFlux equivalent has none. A developer reading both APIs would reasonably infer symmetry that does not exist.
MVC vs WebFlux contrast
Spring MVC delegates through the configured LocaleResolver:
// MVC — RequestContext.changeLocale()
public void changeLocale(Locale locale) {
LocaleResolver localeResolver =
RequestContextUtils.getLocaleResolver(this.request);
if (localeResolver == null) {
throw new IllegalStateException(
"Cannot change locale if no LocaleResolver configured");
}
localeResolver.setLocale(this.request, this.response, locale);
}
WebFlux updates a private field:
// WebFlux — RequestContext.changeLocale()
public void changeLocale(Locale locale) {
this.locale = locale;
}
MVC also fails loudly when no resolver is configured — the IllegalStateException tells the developer they have a wiring problem. WebFlux always succeeds silently.
Path forward
Add Javadoc to both changeLocale() overloads clearly stating that the method affects only the current rendering context, does not delegate through LocaleContextResolver, and does not persist beyond the current request. Cross-reference the recommended approach for durable locale switching in WebFlux.
Happy to open a PR about it if this works with you
A follow-on enhancement to introduce reactive delegation through LocaleContextResolver will be filed separately, dependent on #36569 landing first.
Affects
Spring WebFlux RequestContext — all currently supported versions.
See also
#36569 (Add CookieLocaleContextResolver to Spring WebFlux) — the Javadoc fix above is independent and immediately actionable; reactive delegation as a follow-on depends on or follows from that work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Spring WebFlux RequestContext.changeLocale(Locale) overloads and compare their Javadoc with the MVC equivalent. Document that the change is limited to the current rendering context, does not delegate through LocaleContextResolver, and is not persisted; cross-reference the recommended WebFlux approach for durable locale switching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100