Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8025547

Locale.toString() documentation error

XMLWordPrintable

    • b97
    • generic
    • generic
    • Verified

      Locale.toString()'s Javadoc states:

          Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:

              language + "_" + country + "_" + (variant + "_#" | "#") + script + "-" + extensions

      and one of its examples is:

              zh_TW_#Hant-x-java

      Both of these are incorrect from a reading of the code. The separator between script and extensions is "_", not "-".

      The behavior of the code actually makes some sense to me -- as using "_" would seem to make it a bit easier to parse the result if you need to. In any case, the code or the Javadoc should be corrected -- one or the other.

      All that said, the lack of any utility to do this parsing makes preserving script and extension information embedded in Locale.toString() output a dubious proposition. That's rather unfortunate given existing code that treated Locale.toString() output as a robust interchange representation of Locale objects.

       I have read and understood the Javadoc about this -- and agree that the language tag format is a better, more standardized interchange format. Still, the lack of an API to robustly roundtrip Locale.toString() output back to fully equivalent Locale objects is rather unfortunate -- given where it leaves existing code.

            rgoel Rachna Goel (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: