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

General contract for hashCode() method is broken in java.net.SocketPermission

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3
    • None
    • 6
    • core-libs
    • x86
    • solaris

    Description

      General contract for Object.hashCode() method reads:

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

      In java.net.SocketPermission implementation of equals/hashCode methods this contract is broken. For the code below:


              SocketPermission sp1 = new SocketPermission("localhost", "accept");
              SocketPermission sp2 = new SocketPermission("127.0.0.1", "accept");
              System.out.println("sp1.equals(sp2)=" + sp1.equals(sp2));
              System.out.println("sp1.hashCode()=" + sp1.hashCode()
                      + ", sp2.hashCode()=" + sp2.hashCode());

      we can see the following output:

      sp1.equals(sp2)=true
      sp1.hashCode()=-1204607085, sp2.hashCode()=1505998205

      Which is incorrect according to the contract for Object.hashCode(), moreover the same statement is repeated in java.security.Permission.hashCode() specification:
      "If two Permission objects are equal according to the equals method, then calling the hashCode method on each of the two Permission objects must produce the same integer result."

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mismirno Mikhail Smirnov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: