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

Duration.hashCode() is inconsistent with the definition of the equals method

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b35
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description


      Name: erR10175 Date: 12/26/2003


       
        The following methods of the class javax.xml.datatype.Duration

      public int hashCode()

      returns different values for some equal durations.

      Javadoc of the method reads:

      "Returns a hash code consistent with the definition of the equals method."

      So, the method is expected to return the same values for equal durations.
      For example, one day ("P1D") is equal to 24 hours ("PT24H"). Hash codes
      of the durations must be equal.

      This bug affects new tests in JCK 1.5 (not integrated yet)
          api/javax_xml/datatype/Duration/index.html#Duration[HashCode001]

      The bug is found in jdk1.5.0/beta/b32.

      To reproduce the bug compile and run the following code as shown
      in the log below:
      ------------------------------------------ test.java
      import javax.xml.datatype.Duration;

      public class test {
          public static void main(String [] args) {
              int hc1 = new Duration("P1D").hashCode();
              int hc2 = new Duration("PT24H").hashCode();
              if (hc1 != hc2) {
                  System.out.println("Failed: 'P1D'.hashCode() = " + hc1
                   + " differs from 'PT24H'.hashCode() = " + hc2);
              } else {
                  System.out.println("OK");
              }
          }
      }
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java && java -cp . -showversion test java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

      Failed: 'P1D'.hashCode() = 1 differs from 'PT24H'.hashCode() = 24
      ----------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            jfialli Joe Fialli
            Reporter:
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: