-
Bug
-
Resolution: Fixed
-
P3
-
None
-
None
-
b29
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084976 | emb-9 | Michael McMahon | P3 | Resolved | Fixed | team |
there is a major bug with HttpsURLConnection as it breaks
the contract of equals. So the instance cannot be contained (mostly
removed) in any collection reliably. (Concurrent)HashMap has a provision to
test equality by reference prior calling equals, though.
Finding the bug in production is quite a ride as the http variant doesn't
exhibit the problem.
Here is a simple test case.
public static void main(String[] args) throws Throwable{
URLConnection c = new URL("https://oracle.com").openConnection();
System.out.println(c.getClass().getName()+" equals self: "
+c.equals(c));
c.getInputStream().close();
System.out.println(c.getClass().getName()+" equals self: "
+c.equals(c));
}
The culprit is in HttpsURLConnectionImpl.equals that blindly calls
delagate.equals:
//// BUG >>>> Not comparing with the delegate
public boolean equals(Object obj) {
return delegate.equals(obj);
}
It should be changed to:
public boolean equals(Object obj) {
return this==obj || (obj instanceof HttpsURLConnectionImpl) &&
delegate.equals( ((HttpsURLConnectionImpl)obj).delegate );
}
the contract of equals. So the instance cannot be contained (mostly
removed) in any collection reliably. (Concurrent)HashMap has a provision to
test equality by reference prior calling equals, though.
Finding the bug in production is quite a ride as the http variant doesn't
exhibit the problem.
Here is a simple test case.
public static void main(String[] args) throws Throwable{
URLConnection c = new URL("https://oracle.com").openConnection();
System.out.println(c.getClass().getName()+" equals self: "
+c.equals(c));
c.getInputStream().close();
System.out.println(c.getClass().getName()+" equals self: "
+c.equals(c));
}
The culprit is in HttpsURLConnectionImpl.equals that blindly calls
delagate.equals:
//// BUG >>>> Not comparing with the delegate
public boolean equals(Object obj) {
return delegate.equals(obj);
}
It should be changed to:
public boolean equals(Object obj) {
return this==obj || (obj instanceof HttpsURLConnectionImpl) &&
delegate.equals( ((HttpsURLConnectionImpl)obj).delegate );
}
- backported by
-
JDK-8084976 HttpsURLConnection.equals() broken
-
- Resolved
-