RFR: 8304286: java/net/SocketOption/OptionsTest.java failing after JDK-8302659
Daniel Jeliński
djelinski at openjdk.org
Thu Mar 16 20:19:40 UTC 2023
On Thu, 16 Mar 2023 19:47:13 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> I don't think so; if all interfaces are skipped, the test will fail - setting a null interface is not permitted.
>>
>> Other multicast-related tests do similar things:
>> - `java/net/MulticastSocket/TestInterfaces.java` [skips interfaces that throw an exception](https://github.com/openjdk/jdk/blob/master/test/jdk/java/net/MulticastSocket/TestInterfaces.java#L103)
>> - `NetworkConfiguration.multicastInterfaces` [skips interfaces that don't have a network address](https://github.com/openjdk/jdk/blob/master/test/lib/jdk/test/lib/NetworkConfiguration.java#L198); we can't do that here because we're testing with a security manager and can't retrieve addresses.
>
> Could you try something like to find an interface with an IP address configured:
>
> boolean preferIPv4 = Boolean.getBoolean("java.net.preferIPv4Stack");
> Class<? extends InetAddress> clazz = preferIPv4 ? Inet4Address.class : Inet6Address.class;
> var ni = NetworkInterface.networkInterfaces()
> .filter(_ni -> _ni.inetAddresses().anyMatch(clazz::isInstance))
> .findAny()
> .orElse(null);
Yeah, I had something like that before. With security manager installed it will only return the loopback interface, which is not usable for multicasting on Linux.
The test is using [this SecurityManager policy](https://github.com/openjdk/jdk/blob/master/test/jdk/java/net/SocketOption/options.policy), which only allows `connect` to `localhost`, so only loopback address will be visible on NetworkInterfaces because of [this check](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/net/NetworkInterface.java#L143)
-------------
PR: https://git.openjdk.org/jdk/pull/13061
More information about the net-dev
mailing list