-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b161
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8176969 | 10 | Mark Sheppard | P3 | Resolved | Fixed | b03 |
(as reported by a colleague)
When a NetworkInterface does not (yet) have any addresses, then getInterfaceAddresses should return an empty list, but it throws NullPointerException instead.
public class EmptyNetworkInterface {
public static void main(String[] args) throws Exception {
// throws NPE
new java.net.MulticastSocket()
.getNetworkInterface()
.getInterfaceAddresses();
}
}
Exception in thread "main" java.lang.NullPointerException
at java.base/java.net.NetworkInterface.getInterfaceAddresses(NetworkInterface.java:179)
Colleague's suggested fix:
@@ -90,6 +90,7 @@ public final class NetworkInterface {
this.name = name;
this.index = index;
this.addrs = addrs;
+ this.bindings = new InterfaceAddress[0];
}
/**
(or add more null checks?)
When a NetworkInterface does not (yet) have any addresses, then getInterfaceAddresses should return an empty list, but it throws NullPointerException instead.
public class EmptyNetworkInterface {
public static void main(String[] args) throws Exception {
// throws NPE
new java.net.MulticastSocket()
.getNetworkInterface()
.getInterfaceAddresses();
}
}
Exception in thread "main" java.lang.NullPointerException
at java.base/java.net.NetworkInterface.getInterfaceAddresses(NetworkInterface.java:179)
Colleague's suggested fix:
@@ -90,6 +90,7 @@ public final class NetworkInterface {
this.name = name;
this.index = index;
this.addrs = addrs;
+ this.bindings = new InterfaceAddress[0];
}
/**
(or add more null checks?)
- backported by
-
JDK-8176969 NetworkInterface.getInterfaceAddresses throws NPE when no addresses
-
- Resolved
-