JDK-6798979 : NetworkInterface.getNetworkInterfaces() handles multiple loopbacks incorrectly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-01-29
  • Updated: 2011-02-16
Description
FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600] (Russian) 32-bit

EXTRA RELEVANT SYSTEM CONFIGURATION :
AMD Sempron Processor 2800+
IP Helper API 5.1.2600.5512 (xpsp.080413-0852)

One Ethernet card, one PPP connection over GPRS

A DESCRIPTION OF THE PROBLEM :
Due to a bug in native code (enumInterfaces_win function in NetworkInterface.c) when multiple loopback interfaces are present in the system, getNetworkInterfaces() method return incomplete list of interfaces.

The reason is that when loopback interface already found and switch encounters it again, it continues the loop without incrementing ifrowP pointer.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Have machine with one connected ethernet interface and one connected PPP interface. This results in three UP interfaces (lo, eth0 and ppp0).

Now navigate to Control pannel -> Network Connections and create new incoming connection:

(New Connection Wizard -> Set up an advanced connection (so that other computers can connect) -> Accept incoming connections -> Select using standard modem -> Allow virtual private connections -> Next -> Next -> Next -> Finish)



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
lo
eth0
ppp0

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class Main {
    public static void main(String[] args) throws SocketException {
        Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
        for (NetworkInterface ni : Collections.list(nis)) {
            System.out.println(ni.getName());
        }
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Remove duplicate loopback interface by deleting Incoming connection

Comments
EVALUATION Our code assumes that there is only one IPv4 loopback interface. We need to :- 1) make sure nothing else is depending on this (incorrect) assumption. 2) come up with a naming scheme for subsequent loopback interfaces eg. "lo" --> "lo1" --> "lo2" ie. probably can't change name of first loopback. 3) then remove that continue statement to remove the restriction.
23-08-2010