Skip to content

Commit

Permalink
Adjust for removed locale provider in JDK 23 and newer
Browse files Browse the repository at this point in the history
JDK 23 removes the COMPAT/JRE locale provider
which causes some changes to string formatting

Some currency formatting relied on COMPAT to
format US-Dollar, we should override this to
keep the formatting the same way as Excel and
LibreOffice.

Also some tests for Chinese tried to work
around when COMPAT was used, this needs to
take JDK 23 into account when checking

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1922500 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Dec 14, 2024
1 parent 3755101 commit ba6b755
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ private static ValueEval evaluateDollar(ValueEval[] args, int srcRowIndex, int s
DecimalFormat nf = (DecimalFormat) NumberFormat.getCurrencyInstance(LocaleUtil.getUserLocale());
int decimalPlaces = Math.max(nPlaces, 0);
if (LocaleUtil.getUserLocale().getCountry().equalsIgnoreCase("US")) {
nf.setNegativePrefix("(" + nf.getDecimalFormatSymbols().getCurrencySymbol());
// Java 23 removed "COMPAT" locale provider and thus
// we need to ensure that the dollar-sign is used and not "USD" as Java 23 and newer
// would do
nf.setPositivePrefix("$");
nf.setNegativePrefix("($");
nf.setNegativeSuffix(")");
}
nf.setMinimumFractionDigits(decimalPlaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,26 @@ void test60369(Locale locale, String expected, Date d, int month) {
* is expected and selected via an index
*/
private static int localeIndex(Locale locale) {
return jreVersion < 9 ||
!locale.equals (Locale.CHINESE) ||
(provider != null && (provider.startsWith("JRE") || provider.startsWith("COMPAT")))
? 0 : 1;
if (jreVersion < 9) {
return 0;
}

// only Chinese needs special handling
if (!locale.equals (Locale.CHINESE)) {
return 0;
}

// in JDK 23, the COMPAT/JRE provider was removed completely
if (jreVersion >= 23) {
return 1;
}

// check if the JRE/COMPAT locale provide is selected
if (provider != null && (provider.startsWith("JRE") || provider.startsWith("COMPAT"))) {
return 0;
}

return 1;
}

/**
Expand Down

0 comments on commit ba6b755

Please sign in to comment.