You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I faced something strange when instantiating CurrencyUnit from the currencyCode string.
Some strings like "X*", "X+|" and others were allowed to create a currency.
Here is a small test to exemplify the situation and some comparison with java.util.Currency:
@TestvoidmonetaCurrencyUnit() {
// SOME STRANGE STRINGS ARE ALLOWED! The test PASSEDMonetary.getCurrency("X*");
Monetary.getCurrency("X*|helloWorld");
Monetary.getCurrency("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
}
@TestvoidmonetaCurrencyUnitLowerHistorical() {
// This fails as I was expecting, and that led me think that the Moneta impl of currency is more sound.// Because on the other hand, when using java.util.Currency, it works.Monetary.getCurrency("EUr");
}
@TestvoidjdkCurrency() {
// Both throw exception as I would expect (not the case in Moneta `CurrencyUnit`: `Monetary.getCurrency()`)java.util.Currency.getInstance("X*");
java.util.Currency.getInstance("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
}
@TestvoidjdkCurrencyLowerHistorical() {
// I was not expecting this, but only some currencies work when the last char is lowercase like:java.util.Currency.getInstance("ESp"); // YUm ok, BEf ok, DEm ok, ADp ok (they're all historical currencies), EUr also works
}
The text was updated successfully, but these errors were encountered:
gerardbosch
changed the title
Strange currency code strings like "X*" allow to create a CurrencyUnit
Strange currency code strings like X+|\u0019F allow to create a CurrencyUnitFeb 5, 2025
I faced something strange when instantiating
CurrencyUnit
from thecurrencyCode
string.Some strings like
"X*"
,"X+|"
and others were allowed to create a currency.Here is a small test to exemplify the situation and some comparison with
java.util.Currency
:The text was updated successfully, but these errors were encountered: