尹茂椿萱 created LANG-1823:
--------------------------
Summary: LocaleUtils.toLocale cannot parse valid JDK Locale string
containing '#' (e.g., from Locale.getAvailableLocales())
Key: LANG-1823
URL: https://issues.apache.org/jira/browse/LANG-1823
Project: Commons Lang
Issue Type: Bug
Affects Versions: 3.20.0
Reporter: 尹茂椿萱
{{LocaleUtils.toLocale(String)}} claims to strictly validate and convert a
locale string into a {{Locale}} object. However, it fails to parse certain
valid locale strings produced by the JDK itself.
Specifically, some {{Locale}} instances returned by
{{java.util.Locale#getAvailableLocales()}} produce string representations (via
{{{}toString(){}}}) that contain a {{#}} character (e.g.,
{{{}"th_TH_#Thai"{}}}). These strings cannot be parsed by
{{{}LocaleUtils.toLocale{}}}, resulting in an {{{}IllegalArgumentException{}}}.
This creates an inconsistency where valid JDK locale representations cannot be
round-tripped through {{{}LocaleUtils{}}}.
h3. *Steps to Reproduce*
{{import java.util.Locale;}}
{{import org.apache.commons.lang3.LocaleUtils;}}
{{public class Repro {}}
{{ public static void main(String[] args) {}}
{{ for (Locale locale : Locale.getAvailableLocales()) {}}
{{ String str = locale.toString();}}
{{ try {}}
{{ Locale parsed = LocaleUtils.toLocale(str);}}
{{ } catch (Exception e) {}}
{{ System.out.println("FAIL: " + str);}}
{{ }}}
{{ }}}
{{ }}}
{{}}}
----
h3. *Observed Behavior*
Example failing output:
{{FAIL: th_TH_#Thai}}
{{LocaleUtils.toLocale("th_TH_#Thai")}} throws {{{}IllegalArgumentException{}}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)