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

java.net.InterfaceAddress's equals method may throw NPE

XMLWordPrintable

    • b22
    • generic
    • generic

        InterfaceAddress.equals contains this:

        if ((address != null & cmp.address == null) ||
            (!address.equals(cmp.address)))
            return false;
        if ((broadcast != null & cmp.broadcast == null) ||
            (!broadcast.equals(cmp.broadcast)))
            return false;

        if address == null, or broadcast == null, NPE will be thrown. broadcast ==
        null can be tested by running this test:

        try {
           Enumeration<NetworkInterface> networkInterfaces =
              NetworkInterface.getNetworkInterfaces();

           while (networkInterfaces.hasMoreElements()) {
              NetworkInterface networkInterface = networkInterfaces.nextElement();

              List<InterfaceAddress> interfaceAddresses =
                 networkInterface.getInterfaceAddresses();

              for (InterfaceAddress interfaceAddress : interfaceAddresses) {
                 interfaceAddress.equals(interfaceAddress);
              }
           }
        } catch (SocketException ex) {
           ex.printStackTrace();
        }

        When the loopback interface address is reached, NPE will be thrown for the
        broadcast test. I'm not sure if you can get an interface address with a null
        address.

        This has been fixed in JDK 7.

              robm Robert Mckenna
              dmocek Darryl Mocek
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: