From 48a592be5a11afd43a08cd92ba40a525ae8bf7e2 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Wed, 13 Feb 2013 11:49:34 -0800 Subject: [PATCH] 8008161: Regression: j.u.TimeZone.getAvailableIDs(rawOffset) returns non-sorted list To return a sorted list Reviewed-by: lancea, naoto --- .../sun/util/calendar/ZoneInfoFile.java | 8 +++++++- .../sun/util/calendar/zi/TestZoneInfo310.java | 20 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java b/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java index ab1cf5c6dc9..2bddab21f2d 100644 --- a/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java +++ b/jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java @@ -92,7 +92,13 @@ public final class ZoneInfoFile { ids.add(id); } } - return ids.toArray(new String[ids.size()]); + // It appears the "zi" implementation returns the + // sorted list, though the specification does not + // specify it. Keep the same behavior for better + // compatibility. + String[] list = ids.toArray(new String[ids.size()]); + Arrays.sort(list); + return list; } public static ZoneInfo getZoneInfo(String zoneId) { diff --git a/jdk/test/sun/util/calendar/zi/TestZoneInfo310.java b/jdk/test/sun/util/calendar/zi/TestZoneInfo310.java index c9e2bd9e6f7..f1191c6e90c 100644 --- a/jdk/test/sun/util/calendar/zi/TestZoneInfo310.java +++ b/jdk/test/sun/util/calendar/zi/TestZoneInfo310.java @@ -23,7 +23,7 @@ /* *@test - *@bug 8007572 + *@bug 8007572 8008161 *@summary Test whether the TimeZone generated from JSR310 tzdb is the same *as the one from the tz data from javazic */ @@ -156,6 +156,24 @@ public class TestZoneInfo310 { sun.util.calendar.ZoneInfoFile.getVersion(), ver); throw new RuntimeException("Version test failed"); } + + // test getAvailableIDs(raw); + zids_new = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); + //Arrays.sort(zids_new); + zids_old = ZoneInfoOld.getAvailableIDs(-8 * 60 * 60 * 1000); + if (!Arrays.equals(zids_new, zids_old)) { + System.out.println("------------------------"); + System.out.println("NEW.getAvailableIDs(-8:00)"); + for (String zid : zids_new) { + System.out.println(zid); + } + System.out.println("------------------------"); + System.out.println("OLD.getAvailableIDs(-8:00)"); + for (String zid : zids_old) { + System.out.println(zid); + } + throw new RuntimeException(" FAILED: availableIds(offset) don't match"); + } } private static void delete(File f) {