test/jdk/java/net/SocketPermission/SocketPermissionTest.java question about Optional usage in joinGroupMulticastTest()
Daniel Fuchs
daniel.fuchs at oracle.com
Tue Jul 6 14:01:54 UTC 2021
Thanks Matthias,
It does look like a bug. We probably have at least one
IPv4 multicast interfaces on all machines in our CI!
Not sure whether randomly selecting the first one is such
a good idea though - we may have to investigate how
stable the test gets if we fix this...
best regards,
-- daniel
On 06/07/2021 13:26, Baesken, Matthias wrote:
> 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
> <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
>
More information about the net-dev
mailing list