JDK-4726030 : GregorianCalendar doesn't check invalid dates in non-lenient
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-08-05
  • Updated: 2003-11-05
  • Resolved: 2003-11-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b28Fixed
Related Reports
Relates :  
Description
GregorianCalendar validates the field values before resolving the calendar fields set by an application. As a result, it performs lenient operations in non-lenient mode. The following is a sample program.

--
import java.util.*;


public class Feb29 {
    public static void main(String[] args) {
        GregorianCalendar gcal = new GregorianCalendar();
        gcal.clear();
        gcal.setLenient(false);
        //gcal.set(gcal.YEAR, 1970);
        gcal.set(gcal.MONTH, gcal.FEBRUARY);
        gcal.set(gcal.DAY_OF_MONTH, 29);
        Date date = gcal.getTime();
        System.out.println(date);
    }
}

---
The output:

% java Feb29
Sun Mar 01 00:00:00 JST 1970

If the comment line is enabled, it throws an exception.

% java Feb29
Exception in thread "main" java.lang.IllegalArgumentException
        at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:1519)
        at java.util.Calendar.updateTime(Calendar.java:1552)
        at java.util.Calendar.getTimeInMillis(Calendar.java:912)
        at java.util.Calendar.getTime(Calendar.java:888)
        at Feb29.main(Feb29.java:12)


Comments
EVALUATION No, it's not. Please refer to the test case in: test/java/util/Calendar/NonLenientTest.java
29-01-2008

EVALUATION I guess in Description by mistake wrong line get commented. It should be // gcal.setLenient(false); in place of //gcal.set(gcal.YEAR, 1970);
29-01-2008

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta
14-06-2004

EVALUATION More robust validation is needed. ###@###.### 2002-08-05
05-08-2002