8238231: Custom DatagramSocketImpl's create method not called when with protected constructor

Alan Bateman Alan.Bateman at oracle.com
Sun Feb 2 09:13:15 UTC 2020


On 31/01/2020 21:42, Daniel Fuchs wrote:
>
> Yes. Well I syncronized on `this` because other methods such as
> `bind` or `connectInternal` already synchronize on `this`.
> If the impl has not been created it's more likely that it will
> be by one of these.
Okay.

Just to summarize on this issue: A DatagramSocket created with a public 
constructors will create the socket eagerly. If DatagramSocket is 
extended to invoke protected constructor then the impl's create method 
is not invoked, instead it will be invoked to created the socket by the 
first usage that requires the socket. The latter behavior is unspecified 
and surprising but anyone with a custom impl has to code defensively 
anyway as so much of that mechanism is under specified.

> :
>
> Yes - I noticed the leak a few days ago. I was waiting for an
> opportunity to push it. Changed as suggested.
>
> http://cr.openjdk.java.net/~dfuchs/webrev_8238231/webrev.03/\
Looks okay, I guess we could fix the 2 -> 4 space indent too, up to you.

-Alan.


More information about the net-dev mailing list