Search code examples
javajava-8localejava-11openjdk-11

Different grouping separator for same Locale between Java 8 and 11


I am setting the Locale based on language and region and want to parse a BigDecimal number with this setting. But the issue I am facing is that the grouping separators are different for both OpenJDKs.

Below is the sample code I am trying to execute with OpenJDK 8 and OpenJDK 11.

Locale l = new Locale.Builder().setLanguage("de").setRegion("CH").build();
System.out.println("Locale set to " + Locale.getDefault(Locale.Category.FORMAT));
DecimalFormat nf = (DecimalFormat)NumberFormat.getInstance(Locale.getDefault(Locale.Category.FORMAT));
System.out.println("Grouping Separator: " + nf.getDecimalFormatSymbols().getGroupingSeparator());

Output

OpenJDK 8
---------
Locale set to de_CH
Grouping Separator: '


OpenJDK 11
----------
Locale set to de_CH
Grouping Separator: ’

I need a common parsing method where the grouping separators are returned the same, so that it is easy to design my unit test and it goes through regardless of whether run using java 8 or 11. Please assist.


Solution

  • This is a correct and defined behavior implemented and described as a new feature in Java 11 release notes that refers to JDK-8203868:

    The locale data based on the Unicode Consortium's CLDR (Common Locale Data Registry) has been updated for JDK 11. Localized digits that are in supplementary planes (such as, those in Indian Chakma script) are substituted with ASCII digits until JDK-8204092 is resolved. Medium and short time patterns for Burmese locale have not been upgraded. When JDK-8209175 is resolved, these patterns will be upgraded.

    For more detail on CLDR release 33, please refer to http://cldr.unicode.org/index/downloads/cldr-33.

    Basically, the locale data were updated to Unicode CLDR v33 effective as of JDK 11.