In ICU4J, Currency#getInstance(Stirng theISOCode) does not validate the input code other than checking 3-alpha. The corresponding method in JDK throws IllegalArgumentException when the input code is invalid.
Currency instance initialized with non ISO 4217 code is not useful at all and JDK implementation makes more sense. We probably should change the behavior aligned to JDK's behavior.
Replying to (Comment 1 yoshito):
JDK 7 added a static method - getAvailableCurrencies. ICU4J should match the new API.
This specific item is tracked by ticket along with some other new JDK APIs.
Currency#getInstance to support 3 different modes. 1) ANY: no code validation 2) SUPPORTED: IAE when the input currency code is not known 3) ACTIVE: IAE when the input currency code is unknown or known - but deprecated.
Above 3 different modes are controlled by an extra enum arg in getInstance method - static Currency getInstance(String code, ValidationOption opt).
The default getInstance(String) uses the mode ACTIVE (which is the closest to JDK's behavior).
Add static Set<Currency> getAvailableCurrencies() (ticket). In addition to this, add static Set<Currency> getAvailableCurrencies(Date d), which includes only currencies available at the given date.
After reviewing the current data structure, I found checking availability of input currency code is a relatively heavy operation. ICU maintains historic currency codes associated with region and active duration. To match the JDK's implementation, it has to filter all non-active currencies by iterating through all regional mapping data.
Because such usage (checking availability by this method) is probably not a common use case, I propose to add a new method for checking availability separated from getInstance, at least for now. Below is the proposed new API.
Update to the previous API proposal. After some discussions about the API signature, we reached to an agreement to make the API a little bit more generic, by specifying data range. Below is the final API signature -
Created a ticket for C - #8093