test/jdk/java/net/SocketPermission/SocketPermissionTest.java question about Optional usage in joinGroupMulticastTest()

Baesken, Matthias matthias.baesken at sap.com
Tue Jul 6 12:26:49 UTC 2021


Hi , I wonder about the coding in SocketPermissionTest.java  joinGroupMulticastTest() :

https://github.com/openjdk/jdk/blob/master/test/jdk/java/net/SocketPermission/SocketPermissionTest.java#L224

            // Positive ( requires a functional network interface )
            Optional<NetworkInterface> onif = probe().ip4MulticastInterfaces().findFirst();
            if (!onif.isPresent()) {
                s.setNetworkInterface(onif.get());

In case of  !onif.isPresent() , we call in the next line  onif get , that leads always to a

java.util.NoSuchElementException: No value present
        at java.util.Optional.get(Optional.java:135)
        at SocketPermissionTest.joinGroupMulticastTest(SocketPermissionTest.java:221)

Is this really intended ?   Should it  be  if (onif.isPresent()) {..}    ?

Best regards, Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20210706/671d089a/attachment.htm>


More information about the net-dev mailing list