JDK-6247963 : REGRESSION: SimpleDateFormat.setLenient (false) behavior changed with jdk1.5.0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,windows_xp
  • CPU: x86
  • Submitted: 2005-03-30
  • Updated: 2010-07-29
  • Resolved: 2005-11-07
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
The following runs without output for jdk1.4.2 and jdk1.3.1. But for jdk1.5.0 it will print
#1: java.text.ParseException: Unparseable date: "2002-08-01T14:00:00 GMT"

  To get the output showing the incompatible (and seems buggy)  parse exception with jdk1.5.0
just do
   javac Test.java
   java Test
for the source below (as Test.java). Note if setLenient(false) is not done
the exception output doesn't happen, e.g. if run "java Test xxx".

Note also that if "GMT" below is extended as "GMT+05:00" or "GMT-05:00", then
    java Test
will get the ParseException output line if jdk1.5.0 is used.

// BEGIN Test.java
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.TimeZone;
import java.util.Locale;

class Test {
	public static void main(String args[]) {
		Locale dl = Locale.ENGLISH;
		TimeZone dt = TimeZone.getTimeZone("PST");
		SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z", dl);
		f1.setTimeZone(dt);
		if (args.length == 0) {
			f1.setLenient(false);
		}

		try {
 			f1.parse("2002-08-01T14:00:00 GMT");
		} catch (ParseException e) {
			System.err.println("#1: " + e);
		}

	}
}
// END

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See the detailed descripton for the source and steps to reproduce. It's only 24 lines.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect no println output when the program is run using jdk1.5.0 via
   java Test
as output indicates an incompatiblity with earlier jdks (and seems wrong anyway).
ACTUAL -
When jdk1.5.0 java is used,
   java Test
gives

#1: java.text.ParseException: Unparseable date: "2002-08-01T14:00:00 GMT"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.TimeZone;
import java.util.Locale;

class Test {
	public static void main(String args[]) {
		Locale dl = Locale.ENGLISH;
		TimeZone dt = TimeZone.getTimeZone("PST");
		SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z", dl);
		f1.setTimeZone(dt);
		if (args.length == 0) {
			f1.setLenient(false);
		}

		try {
 			f1.parse("2002-08-01T14:00:00 GMT"");
		} catch (ParseException e) {
			System.err.println("#1: " + e);
		}

	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I suppose not setting lenient false may serve some folk as a workaround.,

Release Regression From : 4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 2005-03-30 12:40:21 GMT

Comments
EVALUATION Closing this bug report as a duplicate of 6231602. The time zone parsing issue should be addressed by 4705403.
07-11-2005

EVALUATION The behavior was changed as a result of fixing various validation problems in non-lenient, such as 4266783. The validation was changed to see if any field values set by client code are consistent with their normalized values. However, applying this validation policy to the zone offsets is too restrictive. This issue has been addressed in 6231602. However, the SimpleDateFormat.parse method should parse the time zone portion separately from the rest of the calendar values and use a new TimeZone instance to get a Date. (See also 4705403) ###@###.### 2005-04-02 02:07:06 GMT
02-04-2005