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

      The following program shows that Calendar.equals changes the observable state of the calendar. The output I got is:
      Date with equals: Tue May 30 20:25:08 PDT 2000
      Date without equals: Sun Apr 30 20:25:08 PDT 2000
      Calling a.equals(b) should never, ever have any observable effect on a or b.


      import java.util.Calendar;

      public class CalEquals {

          public static void main(String[] args) {
              Calendar cal1 = makeCalendar();
              Calendar cal2 = makeCalendar();
              Calendar cal3 = makeCalendar();
              
              cal1.equals(cal2);
              cal1.set(Calendar.DAY_OF_MONTH, 30);
              cal3.set(Calendar.DAY_OF_MONTH, 30);
              System.out.println("Date with equals: " + cal1.getTime());
              System.out.println("Date without equals: " + cal3.getTime());
          }
          
          private static Calendar makeCalendar() {
              Calendar cal = Calendar.getInstance();
              cal.set(Calendar.MONTH, Calendar.APRIL);
              cal.set(Calendar.DAY_OF_MONTH, 31);
              return cal;
          }
      }


      The Date class has the same problem since JDK1.0.
      ###@###.### 2002-08-05

            okutsu Masayoshi Okutsu
            nlindenbsunw Norbert Lindenberg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: