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.