8220037: Inconsistencies of generated timezone files between Windows and Linux
authornaoto
Tue, 07 May 2019 09:37:02 -0700
changeset 54745 87d01c0d7b45
parent 54744 be7839b9493f
child 54746 61049e91eae5
8220037: Inconsistencies of generated timezone files between Windows and Linux Reviewed-by: rriggs
make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java
test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java
--- a/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java	Tue May 07 07:43:41 2019 -0700
+++ b/make/jdk/src/classes/build/tools/cldrconverter/CLDRConverter.java	Tue May 07 09:37:02 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -346,17 +346,26 @@
                     if (sb.indexOf("root") == -1) {
                         sb.append("root");
                     }
-                    Bundle b = new Bundle(id, sb.toString(), null, null);
-                    // Insert the bundle for root at the top so that it will get
-                    // processed first.
-                    if ("root".equals(id)) {
-                        retList.add(0, b);
-                    } else {
-                        retList.add(b);
-                    }
+                    retList.add(new Bundle(id, sb.toString(), null, null));
                 }
             }
         }
+
+        // Sort the bundles based on id. This will make sure all the parent bundles are
+        // processed first, e.g., for en_GB bundle, en_001, and "root" comes before
+        // en_GB. In order for "root" to come at the beginning, "root" is replaced with
+        // empty string on comparison.
+        retList.sort((o1, o2) -> {
+            String id1 = o1.getID();
+            String id2 = o2.getID();
+            if(id1.equals("root")) {
+                id1 = "";
+            }
+            if(id2.equals("root")) {
+                id2 = "";
+            }
+            return id1.compareTo(id2);
+        });
         return retList;
     }
 
--- a/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java	Tue May 07 07:43:41 2019 -0700
+++ b/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java	Tue May 07 09:37:02 2019 -0700
@@ -23,7 +23,7 @@
 
  /*
  * @test
- * @bug 8005471 8008577 8129881 8130845 8136518 8181157 8210490
+ * @bug 8005471 8008577 8129881 8130845 8136518 8181157 8210490 8220037
  * @modules jdk.localedata
  * @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest
  * @summary Make sure that localized time zone names of CLDR are used
@@ -130,13 +130,10 @@
             System.err.printf("Wrong display name for timezone Etc/GMT-5 : expected GMT+05:00,  Actual " + displayName);
             errors++;
         }
-        if (errors > 0) {
-            throw new RuntimeException("test failed");
-        }
 
         // 8217366: No "no inheritance marker" should be left in the returned array
         // from DateFormatSymbols.getZoneStrings()
-        List.of(Locale.ROOT,
+        errors += List.of(Locale.ROOT,
                 Locale.CHINA,
                 Locale.GERMANY,
                 Locale.JAPAN,
@@ -149,11 +146,26 @@
             .flatMap(zoneStrings -> Arrays.stream(zoneStrings))
             .filter(namesArray -> Arrays.stream(namesArray)
                 .anyMatch(aName -> aName.equals(NO_INHERITANCE_MARKER)))
-            .findAny()
-            .ifPresentOrElse(marker -> {
-                    throw new RuntimeException("No inheritance marker detected with tzid: "
+            .peek(marker -> {
+                 System.err.println("No-inheritance-marker is detected with tzid: "
                                                 + marker[0]);
-                },
-                () -> System.out.println("Success: No \"no inheritance marker\" detected."));
+            })
+            .count();
+
+        // 8220037: Make sure CLDRConverter uniquely produces bundles, regardless of the
+        // source file enumeration order.
+        tz = TimeZone.getTimeZone("America/Argentina/La_Rioja");
+        if (!"ARST".equals(tz.getDisplayName(true, TimeZone.SHORT,
+                                new Locale.Builder()
+                                    .setLanguage("en")
+                                    .setRegion("CA")
+                                    .build()))) {
+            System.err.println("Short display name of \"" + tz.getID() + "\" was not \"ARST\"");
+            errors++;
+        }
+
+        if (errors > 0) {
+            throw new RuntimeException("test failed");
+        }
     }
 }