8217366: ZoneStrings are not populated for all the Locales
authornaoto
Wed, 23 Jan 2019 15:43:01 -0800
changeset 53458 fb34e6aff623
parent 53457 e3ed96060992
child 53459 847f311741b4
8217366: ZoneStrings are not populated for all the Locales Reviewed-by: rriggs
src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java
test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java
--- a/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java	Wed Jan 23 19:56:28 2019 +0100
+++ b/src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java	Wed Jan 23 15:43:01 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 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
@@ -148,6 +148,12 @@
 
     private void deriveFallbackName(String[] names, int index, Locale locale, boolean noDST) {
         if (exists(names, index)) {
+            if (names[index].equals(NO_INHERITANCE_MARKER)) {
+                // CLDR's "no inheritance marker"
+                names[index] = toGMTFormat(names[INDEX_TZID],
+                                    index == INDEX_DST_LONG || index == INDEX_DST_SHORT,
+                                    index % 2 != 0, locale);
+            }
             return;
         }
 
--- a/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java	Wed Jan 23 19:56:28 2019 +0100
+++ b/test/jdk/java/util/TimeZone/CLDRDisplayNamesTest.java	Wed Jan 23 15:43:01 2019 -0800
@@ -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
@@ -73,6 +73,8 @@
         },
     };
 
+    private static final String NO_INHERITANCE_MARKER = "\u2205\u2205\u2205";
+
     public static void main(String[] args) {
         // Make sure that localized time zone names of CLDR are used
         // if specified.
@@ -131,5 +133,27 @@
         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,
+                Locale.CHINA,
+                Locale.GERMANY,
+                Locale.JAPAN,
+                Locale.UK,
+                Locale.US,
+                Locale.forLanguageTag("hi-IN"),
+                Locale.forLanguageTag("es-419")).stream()
+            .peek(System.out::println)
+            .map(l -> DateFormatSymbols.getInstance(l).getZoneStrings())
+            .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: "
+                                                + marker[0]);
+                },
+                () -> System.out.println("Success: No \"no inheritance marker\" detected."));
     }
 }