8001440: CLDR adapter: Invalid number extension in language tag causes exception in NumberFormat.format()
Reviewed-by: okutsu
This commit is contained in:
parent
f1f634eb38
commit
799007c62d
@ -42,7 +42,9 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.spi.DecimalFormatSymbolsProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
@ -554,20 +556,31 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
|
||||
}
|
||||
ResourceBundle rb = adapter.getLocaleData().getNumberFormatData(locale);
|
||||
data = new Object[3];
|
||||
|
||||
// NumberElements look up. First, try the Unicode extension
|
||||
String numElemKey;
|
||||
String numberType = locale.getUnicodeLocaleType("nu");
|
||||
StringBuilder numElemKey =
|
||||
new StringBuilder(numberType != null ?
|
||||
numberType : rb.getString("DefaultNumberingSystem"));
|
||||
if (numElemKey.length() != 0) {
|
||||
numElemKey.append(".");
|
||||
if (numberType != null) {
|
||||
numElemKey = numberType + ".NumberElements";
|
||||
if (rb.containsKey(numElemKey)) {
|
||||
data[0] = rb.getStringArray(numElemKey);
|
||||
}
|
||||
}
|
||||
numElemKey.append("NumberElements");
|
||||
try {
|
||||
data[0] = rb.getStringArray(numElemKey.toString());
|
||||
} catch (MissingResourceException mre) {
|
||||
// numberType must be bogus. Use the last resort numbering system.
|
||||
|
||||
// Next, try DefaultNumberingSystem value
|
||||
if (data[0] == null && rb.containsKey("DefaultNumberingSystem")) {
|
||||
numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements";
|
||||
if (rb.containsKey(numElemKey)) {
|
||||
data[0] = rb.getStringArray(numElemKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Last resort. No need to check the availability.
|
||||
// Just let it throw MissingResourceException when needed.
|
||||
if (data[0] == null) {
|
||||
data[0] = rb.getStringArray("NumberElements");
|
||||
}
|
||||
|
||||
needCacheUpdate = true;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,10 @@ public class LocaleProviders {
|
||||
tzNameTest(args[1]);
|
||||
break;
|
||||
|
||||
case "bug8001440Test":
|
||||
bug8001440Test();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Test method '"+methodName+"' not found.");
|
||||
}
|
||||
@ -93,4 +97,10 @@ public class LocaleProviders {
|
||||
throw new RuntimeException("JRE's localized time zone name for "+id+" could not be retrieved. Returned name was: "+tzName);
|
||||
}
|
||||
}
|
||||
|
||||
static void bug8001440Test() {
|
||||
Locale locale = Locale.forLanguageTag("th-TH-u-nu-hoge");
|
||||
NumberFormat nf = NumberFormat.getInstance(locale);
|
||||
String nu = nf.format(1234560);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# @test
|
||||
# @bug 6336885 7196799 7197573 7198834 8000245 8000615
|
||||
# @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440
|
||||
# @summary tests for "java.locale.providers" system property
|
||||
# @compile -XDignore.symbol.file LocaleProviders.java
|
||||
# @run shell/timeout=600 LocaleProviders.sh
|
||||
@ -245,4 +245,12 @@ PARAM2=
|
||||
PARAM3=
|
||||
runTest
|
||||
|
||||
# testing 8001440 fix.
|
||||
METHODNAME=bug8001440Test
|
||||
PREFLIST=CLDR
|
||||
PARAM1=
|
||||
PARAM2=
|
||||
PARAM3=
|
||||
runTest
|
||||
|
||||
exit $result
|
||||
|
Loading…
Reference in New Issue
Block a user