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

java.util.Date.equals() does not enforce symmetry

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • 6
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      1.6.0_02-b05

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP SP2

      A DESCRIPTION OF THE PROBLEM :
      java.util.Date.equals(Object) method is not symmetric as required by the contract.
      The behavior was observed on both 1.4 and 1.5 versions.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test class provided.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should print:
      false
      false
      ACTUAL -
      true
      false

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Test {
      public static void main(String[] args) {
      java.util.Date a = new java.util.Date();
      java.sql.Timestamp b = new java.sql.Timestamp(a.getTime());
      System.out.println(a.equals(b));
      System.out.println(b.equals(a));
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround.

            okutsu Masayoshi Okutsu
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: