Lukasz Lenart created WW-5737:
---------------------------------
Summary: Treat a blank struts.locale as unset instead of pinning
the locale to Locale.ROOT
Key: WW-5737
URL: https://issues.apache.org/jira/browse/WW-5737
Project: Struts 2
Issue Type: Improvement
Components: Core
Reporter: Lukasz Lenart
Fix For: 8.0.0
Follow-up to WW-5670.
{{Dispatcher.setDefaultLocale(String)}} hands the raw {{struts.locale}} value
to {{LocaleUtils.toLocale}}. With commons-lang3 3.20.0, {{toLocale("")}} does
not throw: it returns {{Locale.ROOT}}, and
{{LocaleUtils.isAvailableLocale(Locale.ROOT)}} is {{true}}. So a configuration
such as
{code:xml}<constant name="struts.locale" value=""/>
{code}
or {{struts.locale=}} in {{struts.properties}} pins every request to the root
locale. {{Accept-Language}} is never consulted, {{getText}} / {{<s:text>}}
resolve against the root bundle only, and nothing is logged because the value
parsed successfully. An operator writing a blank value almost certainly means
"unset". A whitespace-only value ({{" "}}) does throw and takes the unparseable
path, so the two spellings of "nothing" behave differently.
This is long-standing behaviour (the pre-WW-5670 code called the same
{{toLocale}} per request) and was deliberately left unchanged by WW-5670, which
is a diagnostics-only fix.
h2. Proposal
* In {{setDefaultLocale}}, treat a blank value ({{StringUtils.isBlank}}) as
unset: {{defaultLocale = null}}, {{parsedDefaultLocale = null}}. The
request-locale resolution then applies as if the constant had never been set.
* Log at INFO/DEBUG that a blank {{struts.locale}} was ignored, so the change
is visible to anyone who relied on the old behaviour.
* Tests in {{DispatcherTest}}: blank value → request locale is used;
whitespace-only value → same outcome.
* Migration Guide entry: a blank {{struts.locale}} used to select
{{Locale.ROOT}}; applications that want the root locale must set it explicitly
(there is no {{toLocale}} spelling for {{Locale.ROOT}} other than the empty
string, so document the alternative — e.g. overriding {{Dispatcher.getLocale}},
or the {{I18nInterceptor}} / {{LocaleProvider}} route).
Targeted at 8.0.0 because it changes which locale is resolved for an existing
configuration value.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)