JDK-4228369 : Bug parsing Feb. 29, 2000?
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.2.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-04-09
  • Updated: 1999-04-09
  • Resolved: 1999-04-09
Related Reports
Duplicate :  
Description

The following mail documents a problem with parsing
that date February 29, 2000.  I get the correct result
in JDK 1.1.7 but an incorrect result in JDK 1.2.


--Guy



------------- Begin Forwarded Message -------------


X-Sender: ###@###.###
Date: Fri, 09 Apr 1999 09:36:27 -0400
To: Guy Steele - Sun Microsystems Labs <###@###.###>
From: David Chase <###@###.###>


...


Anyway, here's an example.  It is supposed to fail in 1900, 
but not in in 2000.


-------------------------------------------------------
import java.util.TimeZone;
import java.util.Date;
import java.text.SimpleDateFormat;


public class Bug
{
  static public void main(String[] args)
  {
    String[] testStrings = {
      "28/02/1900",
      "29/02/1900",    // should result in an exception
      "28/02/2000",
      "29/02/2000",
    };
    
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    formatter.setLenient(false);
    formatter.setTimeZone(TimeZone.getDefault());
    for (int i = 0; i < testStrings.length; ++i) {
      System.out.println("For test string " + testStrings[i]);
      try  {
        Date d = formatter.parse(testStrings[i]);
        System.out.println("    time = " + d.getTime());
        System.out.println("    result = " + d);
      }
      catch (Exception e) {
        System.out.println();
        e.printStackTrace();
      }
    }
  }
}
-------------------------------------------------------
...


------------- End Forwarded Message ------------- 

Comments
WORK AROUND
11-06-2004

SUGGESTED FIX
11-06-2004

PUBLIC COMMENTS
10-06-2004