[ipv6]: 8224014: Don't run test/jdk/java/net/NetworkInterface/IPv4Only.java in IPv6 only environment

Chris Hegarty chris.hegarty at oracle.com
Thu May 16 10:52:37 UTC 2019


Arthur,

> On 16 May 2019, at 00:24, Arthur Eubanks <aeubanks at google.com> wrote:
> 
> webrev: http://cr.openjdk.java.net/~aeubanks/8224014/webrev.00/ <http://cr.openjdk.java.net/~aeubanks/8224014/webrev.00/>
> bug: https://bugs.openjdk.java.net/browse/JDK-8224014 <https://bugs.openjdk.java.net/browse/JDK-8224014>
> 
> In https://bugs.openjdk.java.net/browse/JDK-8220673 <https://bugs.openjdk.java.net/browse/JDK-8220673>, I missed 
> skipping test/jdk/java/net/NetworkInterface/IPv4Only.java when running in an IPv6 only environment. It should have a call to IPSupport.throwSkippedExceptionIfNonOperational().

After the change for 8223532 in NetworkInterface.c, it is no longer
required that AF_INET sockets be able to be created, coupled with
-Djava.net.preferIPv4Stack=true, enumInterfaces may return NULL, which
in turn bubbles up to the Java layer, in this case getNetworkInterfaces,
as null ( rather than a collection containing the interfaces ).

The specification for NetworkInterface::getNetworkInterfaces guarantees
that there be at least one element in the returned collection, but there
cannot be since the system is mis-configured ( the underlying platform
is IPv6-only coupled with -Djava.net.preferIPv4Stack=true ). The only
sensible thing for the NetworkInterface implementation to do is to throw
an exception ( which is perfectly fine as per its specification,
"java.net.SocketException: No network interfaces configured" ).

Rather than skipping the test, which will clearly work, an alternative
is to ensure that an exception is thrown for this case, e.g.

    if (IPSupport.hasIPv4()) {
        out.println("Testing IPv4");
        Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
        while (nifs.hasMoreElements()) {
            NetworkInterface nif = nifs.nextElement();
            Enumeration<InetAddress> addrs = nif.getInetAddresses();
            while (addrs.hasMoreElements()) {
               InetAddress hostAddr = addrs.nextElement();
               if ( hostAddr instanceof Inet6Address ){
                    throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
               }
            }
        }
    } else {
        // No platform IPv4 support & -Djava.net.preferIPv4Stack=true
        out.println("Testing without IPv4 support");
        try {
            NetworkInterface.getNetworkInterfaces();
        } catch (SocketException expected) {
            out.println("caught expected exception: " + expected);
        }

        try {
            NetworkInterface.networkInterfaces();
        } catch (SocketException expected) {
            out.println("caught expected exception: " + expected);
        }
    }

-Chris.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190516/f7a8faa5/attachment-0001.html>


More information about the net-dev mailing list