JDK-8147071 : java.net.NetworkInterface.getNetworkInterfaces ignores unconfigured interfaces.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8u60,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86_64
  • Submitted: 2015-10-15
  • Updated: 2018-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version 1.8.0_60
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
 3.18.9-hardened #2 SMP Wed Jun 3 16:59:24 PDT 2015 x86_64 Intel(R) Pentium(R) CPU G3440 @ 3.30GHz GenuineIntel GNU/Linux


A DESCRIPTION OF THE PROBLEM :
On Linux, calls to java.net.NetworkInterface.getNetworkInterfaces do not return any interfaces which have no address or only an ipv6 link-local address configured.

On Windows, calls to the same function return all network interfaces, regardless of what kinds of addresses are configured.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
call java.net.NetworkInterface.getNetworkInterfaces and compare the returned values to the interfaces installed in the system.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Ideally I would expect it to return all network interfaces on the system, regardless of configuration state, like it does on Windows.

ACTUAL -
Windows returns all interfaces while Linux returns only interfaces with a configured IPv4 address.  (Note:  I didn't actually test with an IPv6 address other than link-local, but I can't think of a good reason to be ignoring link-local addresses specifically, and that's still not the behaviour presented on the other platform anyway)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {
    /**
     * Program entry point
     *
     * @param args  Command line arguments
     */
    public static void main(String[] args) {
        Enumeration<NetworkInterface> netInterfaces = null;
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
            return;
        }
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface iface = netInterfaces.nextElement();
            System.out.println("NIC " + iface.getName() + "\n");
        }
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Write a helper program in something other than Java...


Comments
Attached test case executed on JDK 8u65 - Fail JDK 8u72 - Fail JDK 9ea - Fail
14-01-2016