mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
8314611: Provide more explicative error message parsing Currencies
Reviewed-by: naoto
This commit is contained in:
parent
df5e6e5d48
commit
3c8a6678fe
2 changed files with 41 additions and 13 deletions
|
@ -319,7 +319,8 @@ public final class Currency implements Serializable {
|
|||
// or in the list of other currencies.
|
||||
boolean found = false;
|
||||
if (currencyCode.length() != 3) {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The input currency code must " +
|
||||
"have a length of 3 characters");
|
||||
}
|
||||
char char1 = currencyCode.charAt(0);
|
||||
char char2 = currencyCode.charAt(1);
|
||||
|
@ -342,7 +343,8 @@ public final class Currency implements Serializable {
|
|||
if (!found) {
|
||||
OtherCurrencyEntry ocEntry = OtherCurrencyEntry.findEntry(currencyCode);
|
||||
if (ocEntry == null) {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The input currency code" +
|
||||
" is not a valid ISO 4217 code");
|
||||
}
|
||||
defaultFractionDigits = ocEntry.fraction;
|
||||
numericCode = ocEntry.numericCode;
|
||||
|
@ -397,7 +399,8 @@ public final class Currency implements Serializable {
|
|||
String country = CalendarDataUtility.findRegionOverride(locale).getCountry();
|
||||
|
||||
if (country == null || !country.matches("^[a-zA-Z]{2}$")) {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The country of the input locale" +
|
||||
" is not a valid ISO 3166 country code");
|
||||
}
|
||||
|
||||
char char1 = country.charAt(0);
|
||||
|
@ -414,7 +417,8 @@ public final class Currency implements Serializable {
|
|||
} else {
|
||||
// special cases
|
||||
if (tableEntry == INVALID_COUNTRY_ENTRY) {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The country of the input locale" +
|
||||
" is not a valid ISO 3166 country code");
|
||||
}
|
||||
if (tableEntry == COUNTRY_WITHOUT_CURRENCY_ENTRY) {
|
||||
return null;
|
||||
|
@ -679,7 +683,8 @@ public final class Currency implements Serializable {
|
|||
*/
|
||||
private static int getMainTableEntry(char char1, char char2) {
|
||||
if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The country code is not a " +
|
||||
"valid ISO 3166 code");
|
||||
}
|
||||
return mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')];
|
||||
}
|
||||
|
@ -690,7 +695,8 @@ public final class Currency implements Serializable {
|
|||
*/
|
||||
private static void setMainTableEntry(char char1, char char2, int entry) {
|
||||
if (char1 < 'A' || char1 > 'Z' || char2 < 'A' || char2 > 'Z') {
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException("The country code is not a " +
|
||||
"valid ISO 3166 code");
|
||||
}
|
||||
mainTable[(char1 - 'A') * A_TO_Z + (char2 - 'A')] = entry;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue