aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2024-12-14 18:53:03 +0000
committerDominik Stadler <centic@apache.org>2024-12-14 18:53:03 +0000
commitba6b7551074858575dce15129006ec435df60605 (patch)
tree2ee444e154c27ca84df1b0c57cab89996e0c7511 /poi
parent3755101b72140ca352f3fb7e97b7a0175c7f6127 (diff)
downloadpoi-ba6b7551074858575dce15129006ec435df60605.tar.gz
poi-ba6b7551074858575dce15129006ec435df60605.zip
Adjust for removed locale provider in JDK 23 and newer
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
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java6
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java24
2 files changed, 25 insertions, 5 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
index bc0ccfe482..a0baba1e13 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
@@ -106,7 +106,11 @@ public abstract class NumericFunction implements Function {
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);
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java b/poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
index 0588c75a77..b3ccd06a4c 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/TestExcelStyleDateFormatter.java
@@ -73,10 +73,26 @@ class TestExcelStyleDateFormatter {
* 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;
}
/**