spring-projects / spring-projects/spring-framework

WebFlux RequestContext.changeLocale() lacks Javadoc for rendering-scope limitation (MVC parity gap)

Open Beginner friendly
#36,738 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.