From cdca28ddbc00ab2bdf25dd10ee59f0c9ff5aaf64 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 19 Aug 2024 21:23:13 +0100 Subject: [PATCH] Handle currency data on Java 21 (#138) * Adjust code so the symbol for currency XXX remains as XXX --- src/main/java/org/joda/money/CurrencyUnit.java | 8 ++++++++ src/test/java/org/joda/money/TestCurrencyUnit.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/org/joda/money/CurrencyUnit.java b/src/main/java/org/joda/money/CurrencyUnit.java index 263e930..a9cc6a2 100644 --- a/src/main/java/org/joda/money/CurrencyUnit.java +++ b/src/main/java/org/joda/money/CurrencyUnit.java @@ -577,6 +577,10 @@ public boolean isPseudoCurrency() { * @return the JDK currency instance, never null */ public String getSymbol() { + // Java 21 currency data uses a symbol, we want to retain this as XXX + if ("XXX".equals(code)) { + return code; + } try { return Currency.getInstance(code).getSymbol(); } catch (IllegalArgumentException ex) { @@ -597,6 +601,10 @@ public String getSymbol() { */ public String getSymbol(Locale locale) { MoneyUtils.checkNotNull(locale, "Locale must not be null"); + // Java 21 currency data uses a symbol, we want to retain this as XXX + if ("XXX".equals(code)) { + return code; + } try { return Currency.getInstance(code).getSymbol(locale); } catch (IllegalArgumentException ex) { diff --git a/src/test/java/org/joda/money/TestCurrencyUnit.java b/src/test/java/org/joda/money/TestCurrencyUnit.java index 67196e8..1bfa1dc 100644 --- a/src/test/java/org/joda/money/TestCurrencyUnit.java +++ b/src/test/java/org/joda/money/TestCurrencyUnit.java @@ -712,6 +712,8 @@ void test_getSymbol_Locale_XXX() { Locale.setDefault(Locale.UK); CurrencyUnit test = CurrencyUnit.of("XXX"); assertThat(test.getSymbol(Locale.FRANCE)).isEqualTo("XXX"); + test = CurrencyUnit.of("XXX"); + assertThat(test.getSymbol(Locale.US)).isEqualTo("XXX"); } finally { Locale.setDefault(loc); }