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

Duration.hashCode() is not stable

    XMLWordPrintable

    Details

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

      Description

      Name: erR10175 Date: 01/26/2004


       
        Repeating invocation of the method

      javax.xml.datatype.Duration.hashCode()

      returns different values for the same Duration instance object.

      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 the same durations.
      But in the test (see below) for a duration "PT24H" the method,
      being called several times, returns different values.

      This bug affects new test in JCK 1.5
          api/javax_xml/datatype/Duration/index.html#Duration[HashCode001]

      The bug is found in jdk1.5.0/beta/b35 and it is reprodusible in jdk1.5.0/beta/b32c.

      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) {
              Duration d = new Duration("PT24H");
              int hc1 = d.hashCode();
              int hc2 = hc1;
              for (int i = 1000; --i >=0 || hc1 == hc2; ) {
                  hc2 = d.hashCode();
              }
              if (hc1 != hc2) {
                  System.out.println("hashCode(PT24H) == " + hc1 + " and " + hc2);
              } else {
                  System.out.println("OK");
              }
          }
      }
      ----------------------------------------------------

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

      hashCode(PT24H) == 1043422016 and 1043426016
      ----------------------------------------------------

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

        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: