Skip to content

Commit

Permalink
Handle currency data on Java 21 (#138)
Browse files Browse the repository at this point in the history
* Adjust code so the symbol for currency XXX remains as XXX
  • Loading branch information
jodastephen authored Aug 19, 2024
1 parent 2e9de47 commit cdca28d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/joda/money/CurrencyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/joda/money/TestCurrencyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit cdca28d

Please sign in to comment.