-
Bug
-
Resolution: Unresolved
-
P3
-
None
-
6
-
x86
-
solaris
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."
"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."
- relates to
-
JDK-6592285 DNS resolution is not required explicitly for SocketPermission.implies/equals methods
-
- Open
-