8228465: HOST locale provider holds wrong era name for GregorianCalendar in US locale
authornaoto
Fri, 26 Jul 2019 13:32:59 -0700
changeset 57549 bfe9696bf57f
parent 57548 1f05f7952295
child 57550 278795ad438a
child 57555 02d3f1d03abb
8228465: HOST locale provider holds wrong era name for GregorianCalendar in US locale Reviewed-by: lancea
src/java.base/share/classes/java/util/Calendar.java
test/jdk/java/util/Locale/LocaleProviders.java
test/jdk/java/util/Locale/LocaleProvidersRun.java
--- a/src/java.base/share/classes/java/util/Calendar.java	Fri Jul 26 15:06:22 2019 -0400
+++ b/src/java.base/share/classes/java/util/Calendar.java	Fri Jul 26 13:32:59 2019 -0700
@@ -2205,7 +2205,8 @@
         }
 
         String calendarType = getCalendarType();
-        if (style == ALL_STYLES || isStandaloneStyle(style) || isNarrowFormatStyle(style)) {
+        if (style == ALL_STYLES || isStandaloneStyle(style) || isNarrowFormatStyle(style) ||
+            field == ERA && (style & SHORT) == SHORT) {
             Map<String, Integer> map;
             map = CalendarDataUtility.retrieveFieldValueNames(calendarType, field, style, locale);
 
--- a/test/jdk/java/util/Locale/LocaleProviders.java	Fri Jul 26 15:06:22 2019 -0400
+++ b/test/jdk/java/util/Locale/LocaleProviders.java	Fri Jul 26 13:32:59 2019 -0700
@@ -28,6 +28,8 @@
 
 public class LocaleProviders {
 
+    private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
+
     public static void main(String[] args) {
         String methodName = args[0];
 
@@ -76,6 +78,10 @@
                 bug8220227Test();
                 break;
 
+            case "bug8228465Test":
+                bug8228465Test();
+                break;
+
             default:
                 throw new RuntimeException("Test method '"+methodName+"' not found.");
         }
@@ -106,7 +112,7 @@
     static void bug7198834Test() {
         LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
         LocaleProviderAdapter.Type type = lda.getAdapterType();
-        if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
+        if (type == LocaleProviderAdapter.Type.HOST && IS_WINDOWS) {
             DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
             String date = df.format(new Date());
             if (date.charAt(date.length()-1) == ' ') {
@@ -133,7 +139,7 @@
 
     // This test assumes Windows localized language/country display names.
     static void bug8010666Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             NumberFormat nf = NumberFormat.getInstance(Locale.US);
             try {
                 double ver = nf.parse(System.getProperty("os.version"))
@@ -215,7 +221,7 @@
     }
 
     static void bug8013903Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             Date sampleDate = new Date(0x10000000000L);
             String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47";
             String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
@@ -241,7 +247,7 @@
     }
 
     static void bug8027289Test(String expectedCodePoint) {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             char[] expectedSymbol = Character.toChars(Integer.valueOf(expectedCodePoint, 16));
             NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.CHINA);
             char formatted = nf.format(7000).charAt(0);
@@ -255,7 +261,7 @@
     }
 
     static void bug8220227Test() {
-        if (System.getProperty("os.name").startsWith("Windows")) {
+        if (IS_WINDOWS) {
             Locale l = new Locale("xx","XX");
             String country = l.getDisplayCountry();
             if (country.endsWith("(XX)")) {
@@ -264,4 +270,20 @@
             }
         }
     }
+
+    static void bug8228465Test() {
+        LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(CalendarNameProvider.class, Locale.US);
+        LocaleProviderAdapter.Type type = lda.getAdapterType();
+        if (type == LocaleProviderAdapter.Type.HOST && IS_WINDOWS) {
+            var names =  new GregorianCalendar()
+                .getDisplayNames(Calendar.ERA, Calendar.SHORT_FORMAT, Locale.US);
+            if (!names.keySet().contains("AD") ||
+                names.get("AD").intValue() != 1) {
+                    throw new RuntimeException(
+                            "Short Era name for 'AD' is missing or incorrect");
+            } else {
+                System.out.println("bug8228465Test succeeded.");
+            }
+        }
+    }
 }
--- a/test/jdk/java/util/Locale/LocaleProvidersRun.java	Fri Jul 26 15:06:22 2019 -0400
+++ b/test/jdk/java/util/Locale/LocaleProvidersRun.java	Fri Jul 26 13:32:59 2019 -0700
@@ -25,7 +25,7 @@
  * @test
  * @bug 6336885 7196799 7197573 7198834 8000245 8000615 8001440 8008577
  *      8010666 8013086 8013233 8013903 8015960 8028771 8054482 8062006
- *      8150432 8215913 8220227
+ *      8150432 8215913 8220227 8228465
  * @summary tests for "java.locale.providers" system property
  * @library /test/lib
  * @build LocaleProviders
@@ -154,6 +154,8 @@
             testRun("HOST", "bug8220227Test", "", "", "");
         }
 
+        //testing 8228465 fix. (Windows only)
+        testRun("HOST", "bug8228465Test", "", "", "");
     }
 
     private static void testRun(String prefList, String methodName,