8129881: JDK-8008577 breaks Nashorn test

8130845: Change to CLDR Locale data in JDK 9 b71 causes SimpleDateFormat parsing errors
8132125: German (Switzerland) formatting broken if CLDR Locale Data is used

Reviewed-by: tbell, okutsu
This commit is contained in:
Naoto Sato 2015-08-03 21:47:50 -07:00
parent 594c515e82
commit 9166dacb21
9 changed files with 206 additions and 94 deletions

View File

@ -0,0 +1,52 @@
#
# 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. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# 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.
#
default: all
include $(SPEC)
include MakeBase.gmk
##########################################################################################
### CLDRConverter needs the JRE time zone names from the java.base source.
define cldrconverter_copytznames
$(MKDIR) -p '$(@D)'
$(RM) '$@'
$(SED) -e "s/package sun.util.resources/package build.tools.cldrconverter/" \
-e "s/extends TimeZoneNamesBundle//" \
-e "s/protected final/static final/" \
< $(<) > $@
endef
$(eval $(call SetupCopyFiles,COPY_INTERIM_CLDRCONVERTER, \
SRC := $(JDK_TOPDIR)/src/java.base/share/classes/sun/util/resources, \
DEST := $(BUILDTOOLS_OUTPUTDIR)/interim_cldrconverter_classes/build/tools/cldrconverter, \
FILES := TimeZoneNames.java, \
MACRO := cldrconverter_copytznames))
##########################################################################################
all: $(COPY_INTERIM_CLDRCONVERTER)

View File

@ -38,8 +38,8 @@ include SetupJavaCompilers.gmk
$(eval $(call SetupJavaCompilation,BUILD_TOOLS_JDK, \
SETUP := GENERATE_OLDBYTECODE, \
ADD_JAVAC_FLAGS := "-Xbootclasspath/p:$(BUILDTOOLS_OUTPUTDIR)/interim_jimage_classes", \
SRC := $(JDK_TOPDIR)/make/src/classes, \
ADD_JAVAC_FLAGS := "-Xbootclasspath/p:$(BUILDTOOLS_OUTPUTDIR)/interim_jimage_classes$(PATH_SEP)$(BUILDTOOLS_OUTPUTDIR)/interim_cldrconverter_classes", \
SRC := $(JDK_TOPDIR)/make/src/classes $(BUILDTOOLS_OUTPUTDIR)/interim_cldrconverter_classes, \
BIN := $(BUILDTOOLS_OUTPUTDIR)/jdk_tools_classes, \
COPY := boot.modules ext.modules))

View File

@ -27,12 +27,15 @@ package build.tools.cldrconverter;
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 {
@ -298,8 +301,8 @@ class Bundle {
continue;
}
if (id.startsWith("en")) {
fillInAbbrs(key, nameMap);
if (id.equals("en")) {
fillInJREs(key, nameMap);
}
}
}
@ -381,7 +384,8 @@ class Bundle {
if (Objects.nonNull(parentsMap)) {
for (Iterator<String> it = myMap.keySet().iterator(); it.hasNext();) {
String key = it.next();
if (Objects.deepEquals(parentsMap.get(key), myMap.get(key))) {
if (!key.equals("numberingScripts") && // real body "NumberElements" may differ
Objects.deepEquals(parentsMap.get(key), myMap.get(key))) {
it.remove();
}
}
@ -621,78 +625,41 @@ class Bundle {
return null;
}
private void fillInAbbrs(String key, Map<String, String> map) {
fillInAbbrs(TZ_STD_LONG_KEY, TZ_STD_SHORT_KEY, map);
fillInAbbrs(TZ_DST_LONG_KEY, TZ_DST_SHORT_KEY, map);
fillInAbbrs(TZ_GEN_LONG_KEY, TZ_GEN_SHORT_KEY, map);
static Object[][] jreTimeZoneNames = TimeZoneNames.getContents();
private void fillInJREs(String key, Map<String, String> map) {
String tzid = null;
// If the standard std is "Standard Time" and daylight std is "Summer Time",
// replace the standard std with the generic std to avoid using
// the same abbrivation except for Australia time zone names.
String std = map.get(TZ_STD_SHORT_KEY);
String dst = map.get(TZ_DST_SHORT_KEY);
String gen = map.get(TZ_GEN_SHORT_KEY);
if (std != null) {
if (dst == null) {
// if dst is null, create long and short names from the standard
// std. ("Something Standard Time" to "Something Daylight Time",
// or "Something Time" to "Something Summer Time")
String name = map.get(TZ_STD_LONG_KEY);
if (name != null) {
if (name.contains("Standard Time")) {
name = name.replace("Standard Time", "Daylight Time");
} else if (name.endsWith("Mean Time")) {
if (!name.startsWith("Greenwich ")) {
name = name.replace("Mean Time", "Summer Time");
if (key.startsWith(CLDRConverter.METAZONE_ID_PREFIX)) {
// Look for tzid
String meta = key.substring(CLDRConverter.METAZONE_ID_PREFIX.length());
if (meta.equals("GMT")) {
tzid = meta;
} else {
for (String tz : CLDRConverter.handlerMetaZones.keySet()) {
if (CLDRConverter.handlerMetaZones.get(tz).equals(meta)) {
tzid = tz;
break;
}
} else if (name.endsWith(" Time")) {
name = name.replace(" Time", " Summer Time");
}
map.put(TZ_DST_LONG_KEY, name);
fillInAbbrs(TZ_DST_LONG_KEY, TZ_DST_SHORT_KEY, map);
}
}
if (gen == null) {
String name = map.get(TZ_STD_LONG_KEY);
if (name != null) {
if (name.endsWith("Standard Time")) {
name = name.replace("Standard Time", "Time");
} else if (name.endsWith("Mean Time")) {
if (!name.startsWith("Greenwich ")) {
name = name.replace("Mean Time", "Time");
}
}
map.put(TZ_GEN_LONG_KEY, name);
fillInAbbrs(TZ_GEN_LONG_KEY, TZ_GEN_SHORT_KEY, map);
}
}
}
} else {
tzid = key.substring(CLDRConverter.TIMEZONE_ID_PREFIX.length());
}
private void fillInAbbrs(String longKey, String shortKey, Map<String, String> map) {
String abbr = map.get(shortKey);
if (abbr == null) {
String name = map.get(longKey);
if (name != null) {
abbr = toAbbr(name);
if (abbr != null) {
map.put(shortKey, abbr);
if (tzid != null) {
for (Object[] jreZone : jreTimeZoneNames) {
if (jreZone[0].equals(tzid)) {
for (int i = 0; i < ZONE_NAME_KEYS.length; i++) {
if (map.get(ZONE_NAME_KEYS[i]) == null) {
String[] jreNames = (String[])jreZone[1];
map.put(ZONE_NAME_KEYS[i], jreNames[i]);
}
}
break;
}
}
private String toAbbr(String name) {
String[] substrs = name.split("\\s+");
StringBuilder sb = new StringBuilder();
for (String s : substrs) {
char c = s.charAt(0);
if (c >= 'A' && c <= 'Z') {
sb.append(c);
}
}
return sb.length() > 0 ? sb.toString() : null;
}
private void convert(CalendarType calendarType, char cldrLetter, int count, StringBuilder sb) {
switch (cldrLetter) {

View File

@ -27,6 +27,7 @@ package build.tools.cldrconverter;
import java.io.File;
import java.io.IOException;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -900,6 +901,12 @@ class LDMLParseHandler extends AbstractLDMLHandler<Object> {
Entry<?> entry = (Entry<?>) currentContainer;
Object value = entry.getValue();
if (value != null) {
String key = entry.getKey();
// Tweak for MonthNames for the root locale, Needed for
// SimpleDateFormat.format()/parse() roundtrip.
if (id.equals("root") && key.startsWith("MonthNames")) {
value = new DateFormatSymbols(Locale.US).getShortMonths();
}
put(entry.getKey(), value);
}
}

View File

@ -80,7 +80,17 @@ public final class TimeZoneNameUtility {
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(TimeZoneNameProvider.class, locale);
TimeZoneNameProvider provider = adapter.getTimeZoneNameProvider();
if (provider instanceof TimeZoneNameProviderImpl) {
return ((TimeZoneNameProviderImpl)provider).getZoneStrings(locale);
String[][] zoneStrings = ((TimeZoneNameProviderImpl)provider).getZoneStrings(locale);
if (zoneStrings.length == 0 && locale.equals(Locale.ROOT)) {
// Unlike other *Name provider, zoneStrings search won't do the fallback
// name search. If the ResourceBundle found for the root locale contains no
// zoneStrings, just use the one for English, assuming English bundle
// contains all the tzids and their names.
zoneStrings= getZoneStrings(Locale.ENGLISH);
}
return zoneStrings;
}
// Performs per-ID retrieval.

View File

@ -0,0 +1,44 @@
/*
* 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 8132125
* @summary Checks Swiss' number elements
*/
import java.text.*;
import java.util.*;
public class Bug8132125 {
public static void main(String[] args) {
Locale deCH = new Locale("de", "CH");
NumberFormat nf = NumberFormat.getInstance(deCH);
String expected = "54'839'483.142"; // i.e. "." as decimal separator, "'" as grouping separator
String actual = nf.format(54839483.1415);
if (!actual.equals(expected)) {
throw new RuntimeException("correct for de_CH: " + expected + " vs. actual " + actual);
}
}
}

View File

@ -146,7 +146,7 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
{"Asia/Macau", "China Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
{"Asia/Taipei", "Taipei Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
{"America/Chicago", "CST", none, Locale.ENGLISH, TextStyle.SHORT},
{"Asia/Taipei", "TST", preferred, Locale.ENGLISH, TextStyle.SHORT},
{"Asia/Taipei", "CST", preferred, Locale.ENGLISH, TextStyle.SHORT},
{"Australia/South", "ACST", preferred_s, Locale.ENGLISH, TextStyle.SHORT},
{"America/Chicago", "CDT", none, Locale.ENGLISH, TextStyle.SHORT},
{"Asia/Shanghai", "CDT", preferred_s, Locale.ENGLISH, TextStyle.SHORT},

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -23,12 +23,13 @@
/*
* @test
* @bug 8005471 8008577
* @bug 8005471 8008577 8129881 8130845
* @run main/othervm -Djava.locale.providers=CLDR CLDRDisplayNamesTest
* @summary Make sure that localized time zone names of CLDR are used
* if specified.
*/
import java.text.*;
import java.util.*;
import static java.util.TimeZone.*;
@ -72,6 +73,8 @@ public class CLDRDisplayNamesTest {
};
public static void main(String[] args) {
// Make sure that localized time zone names of CLDR are used
// if specified.
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
int errors = 0;
for (String[] data : CLDR_DATA) {
@ -87,6 +90,35 @@ public class CLDRDisplayNamesTest {
}
}
}
// for 8129881
tz = TimeZone.getTimeZone("Europe/Vienna");
String name = tz.getDisplayName(false, SHORT);
if (!"CET".equals(name)) {
System.err.printf("error: got '%s' expected 'CET' %n", name);
errors++;
}
// for 8130845
SimpleDateFormat fmtROOT = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.ROOT);
SimpleDateFormat fmtUS = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.US);
SimpleDateFormat fmtUK = new SimpleDateFormat("EEE MMM d hh:mm:ss z yyyy", Locale.UK);
Locale originalLocale = Locale.getDefault();
try {
Locale.setDefault(Locale.ROOT);
fmtROOT.parse("Thu Nov 13 04:35:51 AKST 2008");
fmtUS.parse("Thu Nov 13 04:35:51 AKST 2008");
fmtUK.parse("Thu Nov 13 04:35:51 GMT-09:00 2008");
String dateString = new Date().toString();
System.out.println("Date: "+dateString);
System.out.println("Parsed Date: "+new Date(Date.parse(dateString)).toString());
} catch (ParseException pe) {
System.err.println(pe);
errors++;
} finally {
Locale.setDefault(originalLocale);
}
if (errors > 0) {
throw new RuntimeException("test failed");
}

View File

@ -2630,31 +2630,31 @@ LocaleNames/en_SG/TL=Timor-Leste
LocaleNames/en_SG/VC=St. Vincent & Grenadines
LocaleNames/en_SG/WF=Wallis & Futuna
#in
FormatData/in/MonthNames/0=M01
FormatData/in/MonthNames/1=M02
FormatData/in/MonthNames/2=M03
FormatData/in/MonthNames/3=M04
FormatData/in/MonthNames/4=M05
FormatData/in/MonthNames/5=M06
FormatData/in/MonthNames/6=M07
FormatData/in/MonthNames/7=M08
FormatData/in/MonthNames/8=M09
FormatData/in/MonthNames/9=M10
FormatData/in/MonthNames/10=M11
FormatData/in/MonthNames/11=M12
FormatData/in/MonthNames/0=Jan
FormatData/in/MonthNames/1=Feb
FormatData/in/MonthNames/2=Mar
FormatData/in/MonthNames/3=Apr
FormatData/in/MonthNames/4=May
FormatData/in/MonthNames/5=Jun
FormatData/in/MonthNames/6=Jul
FormatData/in/MonthNames/7=Aug
FormatData/in/MonthNames/8=Sep
FormatData/in/MonthNames/9=Oct
FormatData/in/MonthNames/10=Nov
FormatData/in/MonthNames/11=Dec
FormatData/in/MonthNames/12=
FormatData/in/MonthAbbreviations/0=M01
FormatData/in/MonthAbbreviations/1=M02
FormatData/in/MonthAbbreviations/2=M03
FormatData/in/MonthAbbreviations/3=M04
FormatData/in/MonthAbbreviations/4=M05
FormatData/in/MonthAbbreviations/5=M06
FormatData/in/MonthAbbreviations/6=M07
FormatData/in/MonthAbbreviations/7=M08
FormatData/in/MonthAbbreviations/8=M09
FormatData/in/MonthAbbreviations/9=M10
FormatData/in/MonthAbbreviations/10=M11
FormatData/in/MonthAbbreviations/11=M12
FormatData/in/MonthAbbreviations/0=Jan
FormatData/in/MonthAbbreviations/1=Feb
FormatData/in/MonthAbbreviations/2=Mar
FormatData/in/MonthAbbreviations/3=Apr
FormatData/in/MonthAbbreviations/4=May
FormatData/in/MonthAbbreviations/5=Jun
FormatData/in/MonthAbbreviations/6=Jul
FormatData/in/MonthAbbreviations/7=Aug
FormatData/in/MonthAbbreviations/8=Sep
FormatData/in/MonthAbbreviations/9=Oct
FormatData/in/MonthAbbreviations/10=Nov
FormatData/in/MonthAbbreviations/11=Dec
FormatData/in/DayNames/0=Sun
FormatData/in/DayNames/1=Mon
FormatData/in/DayNames/2=Tue
@ -5570,7 +5570,7 @@ FormatData/fi/AmPmMarkers/1=ip.
# bug 6507067
TimeZoneNames/zh_TW/Asia\/Taipei/1=\u53f0\u5317\u6a19\u6e96\u6642\u9593
TimeZoneNames/zh_TW/Asia\/Taipei/2=TST
TimeZoneNames/zh_TW/Asia\/Taipei/2=CST
# bug 6645271
FormatData/hr_HR/DatePatterns/2=d. MMM y.