RFR 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
Paul Sandoz
paul.sandoz at oracle.com
Wed Jun 3 16:47:17 UTC 2015
On Jun 3, 2015, at 12:46 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> On 02/06/2015 14:37, Paul Sandoz wrote:
>
>> :
>>
>> There is one small area of uncertainty with NetworkInterface. Can the following method ever return null?
>>
>> 342 public static Enumeration<NetworkInterface> getNetworkInterfaces()
>> 343 throws SocketException {
>> 344 NetworkInterface[] netifs = getAll();
>> 345
>> 346 // specified to return null if no network interfaces
>> 347 return netifs != null
>> 348 ? enumerationFromArray(netifs)
>> 349 : null;
>> 350 }
>>
>> Contrary to the comment i cannot find any specification. For the stream returning method, networkInterfaces, i have specified this to return an empty stream, thus it might be good to update the enumeration returning method as well to say whether it returns null or an empty enumeration.
>>
> cc'ing net-dev. AFAIK, getNetworkInterface was originally specified to return null but this was changed in Java SE 8 to always return with at least one element, the loopback interface.
>
> The underlying native getAll might still return null for exception cases (which will cause the SocketException to be thrown on return). So I think you can remove the null check.
>
Ok, i removed it but added an assert for the array being non-null and containing at least one element. I also refined the documentation of the stream returning method in light of this:
http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8081678-enumeration-and-stream/webrev/
Paul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20150603/d77e5c8e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20150603/d77e5c8e/signature-0001.asc>
More information about the net-dev
mailing list