JDK-4722650 : Calendar.equals can throw an exception 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-07-30
  • 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 :  
Relates :  
Description
Calendar.equals throws an IllegalArgumentException if a non-lenient Calendar object is involved. The following is a test case.

--
import java.util.*;

public class CalEq {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        cal.setLenient(false);
        cal.set(cal.MONTH, 100);
        System.out.println(Calendar.getInstance().equals(cal));
    }
}

--
Exception in thread "main" java.lang.IllegalArgumentException
         at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:1504)
         at java.util.Calendar.updateTime(Calendar.java:1544)
         at java.util.Calendar.getTimeInMillis(Calendar.java:912)
         at java.util.Calendar.equals(Calendar.java:1114)
         at java.util.GregorianCalendar.equals(GregorianCalendar.java:510)
         at CalEq.main(CalEq.java:8)

###@###.### 2002-07-30

Comments
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 equals invokes getTimeInMillis() to get Calendar's millisecond value. It throws the exception if it's non-lenient and any calendar field value is out of range. ###@###.### 2002-07-30
30-07-2002