JDK-7026810 : SimpleDateFormat behaves strange
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-03-11
  • Updated: 2012-03-20
  • Resolved: 2011-03-17
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b112)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
MS Windows 6.1.7601

A DESCRIPTION OF THE PROBLEM :
SimpleDateFormat doesn't throw exception, where it should, instead of this giver wrong results

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Runt test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'Y'
	at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769)
	at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576)
	at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:501)
	at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:476)
	at test.TestCal.main(TestCal.java:15)

ACTUAL -
Mon Dec 31 00:00:00 CET 2012
Mon Dec 31 00:00:00 CET 2012
Mon Dec 31 00:00:00 CET 2012
Mon Dec 31 00:00:00 CET 2012

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class TestCal {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD");
		
	
			String bal = "2013-01-01";
			String test2 = "2013-03-03";
		
		
		
			try {
		System.out.println(sdf.parse(bal).toString());
		System.out.println(sdf.parse("2013-01-01").toString());
		System.out.println(sdf.parse(test2).toString());
		System.out.println(sdf.parse("2013-03-03").toString());
		
		
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

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

CUSTOMER SUBMITTED WORKAROUND :
not possible

SUPPORT :
YES

Comments
EVALUATION 'Y' has been assigned to week-year in JDK7. Refer to 4267450 and the latest API doc for JDK7.
17-03-2011

EVALUATION "y" is used for the year, not "Y".
13-03-2011