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

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

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: dfC67450 Date: 06/29/98



      java.text.FieldPosition.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[]){
              FieldPosition c1 = new FieldPosition(0);
              FieldPosition c2 = new FieldPosition(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: 825574528
        hashCode2: 822690944
      -------------------------------------------------

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: