Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4722650

Calendar.equals can throw an exception in non-lenient

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.0
    • core-libs
    • None
    • b28
    • generic
    • generic

      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

            okutsu Masayoshi Okutsu
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: