--- old/src/share/classes/java/text/SimpleDateFormat.java 2015-11-16 18:29:52.248543100 +0530 +++ new/src/share/classes/java/text/SimpleDateFormat.java 2015-11-16 18:29:51.526470900 +0530 @@ -1631,8 +1631,8 @@ } private int matchZoneString(String text, int start, String[] zoneNames) { - for (int i = 1; i <= 4; ++i) { - // Checking long and short zones [1 & 2], + for (int i = 0; i <= 4; ++i) { + // Checking main zone[0], long and short zones [1 & 2], // and long and short daylight [3 & 4]. String zoneName = zoneNames[i]; if (text.regionMatches(true, start, @@ -1657,6 +1657,13 @@ /** * find time zone 'text' matched zoneStrings and set to internal * calendar. + * To fix the Bug 8141243, this method is slightly altered and works like this: + * If nameIndex is matching DST in zoneNames(i.e.nameIndex>2), then tz is assigned to the first timezone (at index 0), + * otherwise "tz" is assigned to the timzone at nameIndex in the zoneNames.This will make sure that, + * if any of the abbreviated timezones(like UTC,IST,PST,etc...) which is also part of the main timezone groups is set properly. + * Also, there is a special condition added for the other virtual timezones which are not part of the main timezones + * like AKST,ACST,AEST,WAT,etc.(i.e. "TimeZone.getTimeZone(zoneNames)" always returns "GMT" for those timezones), + * in which the timezone "tz" is always set to the first timezone in the group(at index 0). */ private int subParseZoneString(String text, int start, CalendarBuilder calb) { boolean useSameName = false; // true if standard and daylight time use the same abbreviation. @@ -1669,26 +1676,36 @@ TimeZone tz = null; String[][] zoneStrings = formatData.getZoneStringsWrapper(); String[] zoneNames = null; - int nameIndex = 0; + int nameIndex = -1; if (zoneIndex != -1) { zoneNames = zoneStrings[zoneIndex]; - if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) { - if (nameIndex <= 2) { + if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) { + if (nameIndex > 0 && nameIndex < 3) { // Check if the standard name (abbr) and the daylight name are the same. useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]); } - tz = TimeZone.getTimeZone(zoneNames[0]); + int index = (nameIndex <= 2) ? nameIndex : 0; + tz = TimeZone.getTimeZone(zoneNames[index]); + if (!("GMT".equals(currentTimeZone.getID()) || "GMT".equals(zoneNames[index])) + && "GMT".equals(tz.getID())) { + tz = TimeZone.getTimeZone(zoneNames[0]); + } } } if (tz == null) { zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID()); if (zoneIndex != -1) { zoneNames = zoneStrings[zoneIndex]; - if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) { - if (nameIndex <= 2) { + if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) { + if (nameIndex > 0 && nameIndex < 3) { useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]); } - tz = TimeZone.getTimeZone(zoneNames[0]); + int index = (nameIndex <= 2) ? nameIndex : 0; + tz = TimeZone.getTimeZone(zoneNames[index]); + if (!("GMT".equals(TimeZone.getDefault().getID()) || "GMT".equals(zoneNames[index])) + && "GMT".equals(tz.getID())) { + tz = TimeZone.getTimeZone(zoneNames[0]); + } } } } @@ -1697,11 +1714,15 @@ int len = zoneStrings.length; for (int i = 0; i < len; i++) { zoneNames = zoneStrings[i]; - if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) { - if (nameIndex <= 2) { + if ((nameIndex = matchZoneString(text, start, zoneNames)) >= 0) { + if (nameIndex > 0 && nameIndex < 3) { useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]); } - tz = TimeZone.getTimeZone(zoneNames[0]); + int index = (nameIndex <= 2) ? nameIndex : 0; + tz = TimeZone.getTimeZone(zoneNames[index]); + if (!("GMT".equals(zoneNames[0]) || "GMT".equals(zoneNames[index])) && "GMT".equals(tz.getID())) { + tz = TimeZone.getTimeZone(zoneNames[0]); + } break; } } @@ -2075,6 +2096,8 @@ if (sign == 0) { /* "GMT" without offset */ calb.set(Calendar.ZONE_OFFSET, 0) .set(Calendar.DST_OFFSET, 0); + // set the timezone "GMT" to internal calendar, since it will not be set later. + setTimeZone(TimeZone.getTimeZone("GMT")); return pos.index; }