--- old/src/java.base/share/classes/java/util/Currency.java 2017-11-10 15:30:23.070418030 -0800 +++ new/src/java.base/share/classes/java/util/Currency.java 2017-11-10 15:30:22.733411731 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,6 @@ import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.InputStream; import java.io.IOException; @@ -42,6 +41,7 @@ import java.util.regex.Pattern; import java.util.regex.Matcher; import java.util.spi.CurrencyNameProvider; +import sun.util.locale.provider.CalendarDataUtility; import sun.util.locale.provider.LocaleServiceProviderPool; import sun.util.logging.PlatformLogger; @@ -348,6 +348,13 @@ * until December 31, 2001, and the Euro from January 1, 2002, local time * of the respective countries. *
+ * If the specified locale
contains "cu" and/or "rg"
+ * Unicode extensions,
+ * the instance returned from this method reflects
+ * the values specified with those extensions. If both "cu" and "rg" are
+ * specified, the currency from "cu" extension supersedes the implicit one
+ * from "rg" extension.
+ *
* The method returns null
for territories that don't
* have a currency, such as Antarctica.
*
@@ -361,12 +368,19 @@
* is not a supported ISO 3166 country code.
*/
public static Currency getInstance(Locale locale) {
- String country = locale.getCountry();
- if (country == null) {
- throw new NullPointerException();
+ // check for locale overrides
+ String override = locale.getUnicodeLocaleType("cu");
+ if (override != null) {
+ try {
+ return getInstance(override.toUpperCase(Locale.ROOT));
+ } catch (IllegalArgumentException iae) {
+ // override currency is invalid. Fall through.
+ }
}
- if (country.length() != 2) {
+ String country = CalendarDataUtility.findRegionOverride(locale).orElse(locale).getCountry();
+
+ if (country == null || !country.matches("^[a-zA-Z]{2}$")) {
throw new IllegalArgumentException();
}
@@ -482,6 +496,12 @@
* locale is the US, while for other locales it may be "US$". If no
* symbol can be determined, the ISO 4217 currency code is returned.
*
+ * If the default {@link Locale.Category#DISPLAY DISPLAY} locale + * contains "rg" (region override) + * Unicode extension, + * the symbol returned from this method reflects + * the value specified with that extension. + *
* This is equivalent to calling * {@link #getSymbol(Locale) * getSymbol(Locale.getDefault(Locale.Category.DISPLAY))}. @@ -498,6 +518,11 @@ * For example, for the US Dollar, the symbol is "$" if the specified * locale is the US, while for other locales it may be "US$". If no * symbol can be determined, the ISO 4217 currency code is returned. + *
+ * If the specified locale
contains "rg" (region override)
+ * Unicode extension,
+ * the symbol returned from this method reflects
+ * the value specified with that extension.
*
* @param locale the locale for which a display name for this currency is
* needed
@@ -507,6 +532,7 @@
public String getSymbol(Locale locale) {
LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(CurrencyNameProvider.class);
+ locale = CalendarDataUtility.findRegionOverride(locale).orElse(locale);
String symbol = pool.getLocalizedObject(
CurrencyNameGetter.INSTANCE,
locale, currencyCode, SYMBOL);