8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale
authornaoto
Wed, 09 Sep 2015 18:17:44 -0700
changeset 32510 7530a468314c
parent 32509 142bd680022d
child 32511 3037b7753a1d
8134384: Continuation of JDK-8130845 : A date string created by Date#toString() is not parseable neither with ENGLISH, US nor ROOT locale Reviewed-by: okutsu
jdk/make/src/classes/build/tools/cldrconverter/Bundle.java
jdk/make/src/classes/build/tools/cldrconverter/CLDRConverter.java
jdk/test/sun/util/resources/TimeZone/Bug6377794.java
jdk/test/sun/util/resources/cldr/Bug8134384.java
--- a/jdk/make/src/classes/build/tools/cldrconverter/Bundle.java	Wed Sep 09 21:57:38 2015 +0000
+++ b/jdk/make/src/classes/build/tools/cldrconverter/Bundle.java	Wed Sep 09 18:17:44 2015 -0700
@@ -27,15 +27,12 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Enumeration;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
-import java.util.ResourceBundle;
 
 class Bundle {
     static enum Type {
@@ -117,6 +114,7 @@
     private final String cldrPath;
     private final EnumSet<Type> bundleTypes;
     private final String currencies;
+    private Map<String, Object> targetMap;
 
     static Bundle getBundle(String id) {
         return bundles.get(id);
@@ -176,6 +174,10 @@
      * visible for the bundle's locale
      */
     Map<String, Object> getTargetMap() throws Exception {
+        if (targetMap != null) {
+            return targetMap;
+        }
+
         String[] cldrBundles = getCLDRPath().split(",");
 
         // myMap contains resources for id.
@@ -398,6 +400,7 @@
             }
         }
 
+        targetMap = myMap;
         return myMap;
     }
 
@@ -632,7 +635,7 @@
         return null;
     }
 
-    static Object[][] jreTimeZoneNames = TimeZoneNames.getContents();
+    static List<Object[]> jreTimeZoneNames = Arrays.asList(TimeZoneNames.getContents());
     private void fillInJREs(String key, Map<String, String> map) {
         String tzid = null;
 
--- a/jdk/make/src/classes/build/tools/cldrconverter/CLDRConverter.java	Wed Sep 09 21:57:38 2015 +0000
+++ b/jdk/make/src/classes/build/tools/cldrconverter/CLDRConverter.java	Wed Sep 09 18:17:44 2015 -0700
@@ -25,6 +25,7 @@
 
 package build.tools.cldrconverter;
 
+import static build.tools.cldrconverter.Bundle.jreTimeZoneNames;
 import build.tools.cldrconverter.BundleGenerator.BundleType;
 import java.io.File;
 import java.nio.file.DirectoryStream;
@@ -564,6 +565,44 @@
 
     private static Map<String, Object> extractZoneNames(Map<String, Object> map, String id) {
         Map<String, Object> names = new HashMap<>();
+
+        // Copy over missing time zone ids from JRE for English locale
+        if (id.equals("en")) {
+            Map<String[], String> jreMetaMap = new HashMap<>();
+            jreTimeZoneNames.stream().forEach(e -> {
+                String tzid = (String)e[0];
+                String[] data = (String[])e[1];
+
+                if (map.get(TIMEZONE_ID_PREFIX + tzid) == null &&
+                    handlerMetaZones.get(tzid) == null) {
+                    // First, check the CLDR meta key
+                    Optional<Map.Entry<String, String>> cldrMeta =
+                        handlerMetaZones.getData().entrySet().stream()
+                            .filter(me ->
+                                Arrays.deepEquals(data,
+                                    (String[])map.get(METAZONE_ID_PREFIX + me.getValue())))
+                            .findAny();
+                    if (cldrMeta.isPresent()) {
+                        names.put(tzid, cldrMeta.get().getValue());
+                    } else {
+                        // check the JRE meta key, add if there is not.
+                        Optional<Map.Entry<String[], String>> jreMeta =
+                            jreMetaMap.entrySet().stream()
+                                .filter(jm -> Arrays.deepEquals(data, jm.getKey()))
+                                .findAny();
+                        if (jreMeta.isPresent()) {
+                            names.put(tzid, jreMeta.get().getValue());
+                        } else {
+                            String metaName = "JRE_" + tzid.replaceAll("[/-]", "_");
+                            names.put(METAZONE_ID_PREFIX + metaName, data);
+                            names.put(tzid, metaName);
+                            jreMetaMap.put(data, metaName);
+                        }
+                    }
+                }
+            });
+        }
+
         for (String tzid : handlerMetaZones.keySet()) {
             String tzKey = TIMEZONE_ID_PREFIX + tzid;
             Object data = map.get(tzKey);
--- a/jdk/test/sun/util/resources/TimeZone/Bug6377794.java	Wed Sep 09 21:57:38 2015 +0000
+++ b/jdk/test/sun/util/resources/TimeZone/Bug6377794.java	Wed Sep 09 18:17:44 2015 -0700
@@ -25,6 +25,7 @@
  *@test
  *@bug 6377794
  *@summary Test case for tzdata2005r support for 9 locales
+ *@run main/othervm -Djava.locale.providers=JRE,SPI Bug6377794
  */
 
 import java.util.Locale;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/util/resources/cldr/Bug8134384.java	Wed Sep 09 18:17:44 2015 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8134384
+ * @summary Tests CLDR TimeZoneNames has English names for all tzids
+ * @run main/othervm -Djava.locale.providers=CLDR Bug8134384
+ */
+
+import java.text.*;
+import java.time.*;
+import java.util.*;
+
+public class Bug8134384 {
+    public static void main(String [] args) {
+        TimeZone original = TimeZone.getDefault();
+
+        try {
+            for (String tz : TimeZone.getAvailableIDs() ) {
+                TimeZone.setDefault(TimeZone.getTimeZone(tz));
+                // Summer solstice
+                String date1 = Date.from(Instant.parse("2015-06-21T00:00:00.00Z")).toString();
+                testParse(Locale.ENGLISH, date1, tz);
+                testParse(Locale.US, date1, tz);
+                testParse(Locale.ROOT, date1, tz);
+                // Winter solstice
+                String date2 = Date.from(Instant.parse("2015-12-22T00:00:00.00Z")).toString();
+                testParse(Locale.ENGLISH, date2, tz);
+                testParse(Locale.US, date2, tz);
+                testParse(Locale.ROOT, date2, tz);
+            }
+        } finally {
+            TimeZone.setDefault(original);
+        }
+    }
+
+    private static void testParse(Locale locale, String date, String tz) {
+        try {
+            new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", locale).parse(date);
+            System.out.println(String.format(Locale.ENGLISH, "OK parsing '%s' in locale '%s', tz: %s", date, locale, tz));
+        } catch (ParseException pe) {
+            throw new RuntimeException(String.format(Locale.ENGLISH, "ERROR parsing '%s' in locale '%s', tz: %s: %s", date, locale, tz, pe.toString()));
+        }
+    }
+}