8238231: Custom DatagramSocketImpl's create method not called when with protected constructor
Alan Bateman
Alan.Bateman at oracle.com
Fri Jan 31 17:10:33 UTC 2020
On 31/01/2020 16:46, Daniel Fuchs wrote:
> Hi,
>
> Please find below a fix for:
>
> 8238231: Custom DatagramSocketImpl's create method not called when
> with protected constructor
> https://bugs.openjdk.java.net/browse/JDK-8238231
>
> This is a behavioral regression introduced by JDK-8236925 [1].
> Thanks Alan for providing a suggested fix. I have chosen
> a slightly different alternative to preserve the previous
> behavior where create() was always called by the public
> constructors (and only lazily after the protected one) [2].
This seems to have a few problems. Consider two threads calling
getImpl() at around the same time. This can only work if "created "is
volatile and you set it to true after impl.create() has been called. In
addition, setting "created" to true in the constructor will confuse
future maintainers as to whether it means the impl object has been
created vs. the socket. Otherwise I agree with the eager creation to
preserve long standing behavior.
-Alan
More information about the net-dev
mailing list