Skip to content

Commit 5f00c87

Browse files
committed
8356450: NPE in CLDRTimeZoneNameProviderImpl for tzdata downgrades after JDK-8342550
Reviewed-by: bpb, jlu, joehw
1 parent 0e0bd64 commit 5f00c87

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ protected String[] getDisplayNameArray(String id, Locale locale) {
9393
switch (namesSuper[i]) {
9494
case "":
9595
// Fill in empty elements
96-
deriveFallbackName(namesSuper, i, locale,
97-
ZoneInfo.getTimeZone(id).toZoneId().getRules().isFixedOffset());
96+
deriveFallbackName(namesSuper, i, locale, isFixedOffset(id));
9897
break;
9998
case NO_INHERITANCE_MARKER:
10099
// CLDR's "no inheritance marker"
@@ -132,7 +131,7 @@ protected String[][] getZoneStrings(Locale locale) {
132131

133132
// Derive fallback time zone name according to LDML's logic
134133
private void deriveFallbackNames(String[] names, Locale locale) {
135-
boolean noDST = ZoneInfo.getTimeZone(names[0]).toZoneId().getRules().isFixedOffset();
134+
boolean noDST = isFixedOffset(names[0]);
136135

137136
for (int i = INDEX_STD_LONG; i <= INDEX_GEN_SHORT; i++) {
138137
deriveFallbackName(names, i, locale, noDST);
@@ -312,4 +311,11 @@ private String toGMTFormat(String id, boolean daylight, Locale l) {
312311
String.format(l, hourFormat, offset / 60, offset % 60));
313312
}
314313
}
314+
315+
// ZoneInfo.getTimeZone() may return null if the tzdata has been
316+
// forcibly downgraded to an older release using TZUpdater
317+
private boolean isFixedOffset(String id) {
318+
var zi = ZoneInfo.getTimeZone(id);
319+
return zi == null || zi.toZoneId().getRules().isFixedOffset();
320+
}
315321
}

0 commit comments

Comments
 (0)