Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6663777

NetworkInterface.isUp() may throw SocketException on subinterfaces

XMLWordPrintable

    • generic
    • solaris

      NetworkInterface.isUp() may throw SocketException on subinterfaces.

      Minimized test:
      ------------------
      import java.net.*;
      import java.util.*;

      public class NITest {
             
          public static void main(String args[]) {
              Set<NetworkInterface> allInterfaces = null;
              try {
                  allInterfaces = getNetworkInterfaces();
              } catch (SocketException ex) {
                  ex.printStackTrace();
              }

              int count = 0;
              boolean passed = true;
              for (NetworkInterface ni: allInterfaces) {
                  System.out.println("ni" + count + ": " + ni);
                  try {
                      System.out.println(" isUp: " + ni.isUp());
                  } catch (Exception e) {
                      System.out.println(" exception: " + e);
                      passed = false;
                  }
                  count++;
                  System.out.println("-----------");
              }
              System.out.println(passed ? "Test passed" : "Test failed");
          }
          
          static void addNetworkInterfaces( Set<NetworkInterface> set, Enumeration<NetworkInterface> e ) {
              while(e.hasMoreElements()){
                  NetworkInterface ni = e.nextElement();
                  set.add( ni );
                  addNetworkInterfaces( set, ni.getSubInterfaces() );
              }
          }

          /**
           * Finds all NetworkInterfaces with subinterfaces
           */
          static Set<NetworkInterface> getNetworkInterfaces() throws SocketException {
              Set<NetworkInterface> res = new HashSet<NetworkInterface>();
              addNetworkInterfaces( res, NetworkInterface.getNetworkInterfaces() );
              return res;
          }
          
      }
      ------------------

      #> java -version
      java version "1.6.0_05-ea"
      Java(TM) SE Runtime Environment (build 1.6.0_05-ea-b05)
      Java HotSpot(TM) Tiered VM (build 1.6.0_05-ea-b05, mixed mode)

      #> java NITest
      ni0: name:lo0 (lo0) index: 1 addresses:
      /0:0:0:0:0:0:0:1%1;
      /127.0.0.1;

        isUp: true
      -----------
      ni1: name:eri0 (eri0) index: 2 addresses:
      /fc00:1068:0:0:203:baff:fe44:8dd8%2;
      /fe80:0:0:0:203:baff:fe44:8dd8%2;
      /10.16.106.226;

        isUp: true
      -----------
      ni2: name:eri0:1 (eri0:1) index: 2 addresses:
      /fc00:1068:0:0:203:baff:fe44:8dd8%2;

        exception: java.net.SocketException: No such device or address
      -----------
      Test failed

      #> ifconfig -a
      lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
              inet 127.0.0.1 netmask ff000000
      eri0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
              inet 10.16.106.226 netmask fffffe00 broadcast 10.16.107.255
      lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
              inet6 ::1/128
      eri0: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 2
              inet6 fe80::203:baff:fe44:8dd8/10
      eri0:1: flags=2080841<UP,RUNNING,MULTICAST,ADDRCONF,IPv6> mtu 1500 index 2
              inet6 fc00:1068::203:baff:fe44:8dd8/64

      #> uname -a
      SunOS moonblade 5.10 Generic sun4u sparc SUNW,Sun-Blade-1000

      --------
      Comment:
      isUp() throws exception on "/fc00:1068:0:0:203:baff:fe44:8dd8%2", but this interface is up and running.


      6 JCK 6b tests:

      api/java_net/MulticastSocket/descriptions.html#setTTL[MulticastSocket1017]
      api/java_net/MulticastSocket/descriptions.html#setTTL[MulticastSocket1018]
      api/java_net/MulticastSocket/descriptions.html#setTTL[MulticastSocket1019]
      api/java_net/MulticastSocket/descriptions.html#setTimeToLive[MulticastSocket1020]
      api/java_net/MulticastSocket/descriptions.html#setTimeToLive[MulticastSocket1021]
      api/java_net/MulticastSocket/descriptions.html#setTimeToLive[MulticastSocket1022]

      fail with a similar cause:

      java.net.SocketException: No such device or address
      at java.net.NetworkInterface.isUp0(Native Method)
      at java.net.NetworkInterface.isUp(NetworkInterface.java:322)
      at javasoft.sqe.tests.api.java.net.MulticastSocket.MulticastSocketSenderTest.execute(MulticastSocketSenderTest.java:95)
      at javasoft.sqe.tests.api.java.net.MulticastSocket.setTTLTests.MulticastSocket1017(setTTLTests.java:66)
      The JCK tests mentioned in description fail on JDK 6.0.

            chegar Chris Hegarty
            dfazunen Dmitry Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: