On Wed, 23 Jun 2021 14:19:59 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:

>> src/java.base/share/classes/java/net/DatagramSocket.java line 1405:
>> 
>>> 1403:                 // create legacy DatagramSocket delegate
>>> 1404:                 DatagramSocketImpl impl = 
>>> factory.createDatagramSocketImpl();
>>> 1405:                 Objects.requireNonNull(impl);
>> 
>> I assume this Objects.requireNonNull is not needed or maybe you want to 
>> detect a buggy factory rather than in the the constructor?
>
> Yes - the constructor would throw NPE - but there's no need to call this 
> constructor if `impl` is null here - it's better to fail early.

This is probably a case where the spec needs say that an error (maybe an 
unspecified error) is thrown if the custom factory's createDatagramSocketImpl 
returns null. We can create a separate issue for that as it's probably existed 
forever.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4574

Reply via email to