RFR 8241305: Add protocol specific factory creation methods to SocketChannel and ServerSocketChannel
Chris Hegarty
chris.hegarty at oracle.com
Tue May 5 15:00:22 UTC 2020
> On 5 May 2020, at 13:53, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> ...
>
> Minor comment is that the requiresNonNull is not really needed in SocketChannel, ServerSocketChannel and DatagramSocket as they just delegate to the provider which is specified to throw NPE already.
These are static methods that delegate to a pluggable provider. As such, it would be better for them to not rely on the null checking behaviour of the actual provider plugged in. A plugged-in provider may mistakenly throw an exception other than NPE, or delegate to a channel constructor which would end up constructing an instance of the channel to only then abandon it mid-initialization. On balance, it seems best to catch any potential bad null as early as possible, rather than waiting for it to (hopefully) be caught later.
-Chris.
More information about the nio-dev
mailing list