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

java.text.ParsePosition.hashCode() returns different values on the equal objects

    XMLWordPrintable

Details

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified

    Description



      Name: dfC67450 Date: 06/29/98



      java.text.ParsePosition.hashCode() returns different results on the equal objects.
      This behaviour is inconsistent with the specification.
      JLS 1.0 item 20.1.4 says:

          If two objects are equal according to the equals method (20.1.3),
          then calling the hashCode method on each of the two objects must
          produce the same integer result.

      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      public class Test {
          public static void main (String args[]){
              ParsePosition c1 = new ParsePosition(0);
              ParsePosition c2 = new ParsePosition(0);
              int hc1 = c1.hashCode();
              int hc2 = c2.hashCode();
              if (c1.equals(c2) & hc1 != hc2) {
                System.out.println("Test failed");
                System.out.println(" hashCode1: " + hc1);
                System.out.println(" hashCode2: " + hc2);
              } else {
                System.out.println("Test passed");
              }
          }
        
      }
      ---------Output from the test---------------------
      Test failed
        hashCode1: 825574862
        hashCode2: 822691278
      -------------------------------------------------

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

      Attachments

        Activity

          People

            aliusunw Alan Liu (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: