sun.net.www.protocol.https.HttpsURLConnectionImpl doesn't equal to self

Michael McMahon michael.x.mcmahon at oracle.com
Mon Aug 18 15:21:43 UTC 2014


I'll file a bug for this Stanimir. Thanks for reporting it.
Should be able to fix it in JDK 9 fairly promptly
and we'll see about back porting it then.

- Michael.

On 18/08/14 15:04, Stanimir Simeonoff wrote:
> Hi,
>
> As the title says 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:
>
>      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 class has some other issue that involves declaring "finalize" method to
> simply call delegate's dispose. The finalize method is unneeded and just
> creates unnecessary link in the finalization queue + Finalizer object.
>
> Thanks
> Stanimir




More information about the core-libs-dev mailing list