--- /dev/null 2015-11-16 18:29:56.000000000 +0530 +++ new/test/java/text/Format/DateFormat/Bug8141243.java 2015-11-16 18:29:55.168835100 +0530 @@ -0,0 +1,108 @@ +/* + * 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 8141243 + * @summary Make sure that Timezone returned after parsing a date with SimpleDateFormat is correct. + * Description: When parsing the virtual timezone "UTC" with java.text.SimpleDateFormat, + * the timezone is set to the first timezone that matches an actual timezone in the UTC group, which is Antarctica/Troll. + * When comparing this timezone with the result of TimeZone.getTimeZone("UTC"), we fail. + * + */ + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class Bug8141243 { + private static int errorCount = 0; + private static final String[] TIMEZONES = { + + "UTC", // Coordinated Universal Time + "IST", // Indian Standard Time + "PST", // Pacific Standard Time + "MST", // Mountain Standard Time + "CST", // Central Standard Time + "EST", // Eastern Standard Time + "HST", // Hawaii Standard Time + "AST", // Atlantic Standard Time + "NST", // Newfoundland Standard Time + "CET", // Central European Time + "GMT", // Greenwich Mean Time + "WET", // Western European Time + "JST", // Japan Standard Time + "EET", // Eastern European Time + "CST", // China Standard Time + "ART", // Argentine Time + "EAT", // Eastern African Time + "CAT", // Central African Time + "ACT", // Acre Time 30 + "ECT", // Ecuador Time + "Greenwich Mean Time" + + }; + + public static void main(String[] args) { + String datePattern = "z"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); + long now = System.currentTimeMillis(); + Date date; + Calendar calendar; + TimeZone timeZone; + + System.out.println("Running Total " + TIMEZONES.length + " tests..."); + for (int i = 0; i < TIMEZONES.length; i++) { + try { + date = simpleDateFormat.parse(TIMEZONES[i]); + calendar = new GregorianCalendar(simpleDateFormat.getTimeZone()); + calendar.setTime(date); + timeZone = TimeZone.getTimeZone(TIMEZONES[i]); + + if (!timeZone.getID().equalsIgnoreCase(calendar.getTimeZone().getID())) { + throw new Exception(" *** TimeZone ID mismatch for test " + (i + 1) + " *** " + timeZone.getID() + + " != " + calendar.getTimeZone().getID()); + } + if (timeZone.getOffset(now) != calendar.getTimeZone().getOffset(now)) { + throw new Exception(" *** TimeZone Offset mismatch for test " + (i + 1) + " *** " + timeZone.getID() + + " != " + calendar.getTimeZone().getID()); + } + System.out.println("Test-" + (i + 1) + " : Works As Expected"); + + } catch (Exception e) { + if (e instanceof ParseException) { + System.err.println("Exception occured while Parsing timezone : " + TIMEZONES[i]); + } else { + System.err.println(e.getMessage()); + } + errorCount++; + } + } + if (errorCount > 0) { + throw new RuntimeException("Test failed with " + errorCount + " error(s)..."); + } + } +}