Hi,
please oblige and review the change
http://cr.openjdk.java.net/~msheppar/8164815/webrev/src/java.base/share/classes/java/net/NetworkInterface.java.sdiff.html
to address the issue raised in
https://bugs.openjdk.java.net/browse/JDK-8164815
It was found during testing that, when a system does not have at least one
configured network interface, the Enumeration is instantiated using a
null value,
which results in an unexpected NPE, when it is used.
this change, adds a specific check of the return value from the getAll()
native method, and throws
a SocketException should a null value have been returned.
regards
Mark
diff -r 4407b0525631
src/java.base/share/classes/java/net/NetworkInterface.java
--- a/src/java.base/share/classes/java/net/NetworkInterface.java Tue Nov
08 16:54:28 2016 -0800
+++ b/src/java.base/share/classes/java/net/NetworkInterface.java Thu Nov
10 14:43:45 2016 +0000
@@ -335,15 +335,19 @@
* {@link #getInetAddresses()} to obtain all IP addresses for this
node
*
* @return an Enumeration of NetworkInterfaces found on this machine
- * @exception SocketException if an I/O error occurs.
+ * @exception SocketException if an I/O error occurs,
+ * or if the System does not have at least one configured
+ * network interface.
* @see #networkInterfaces()
*/
public static Enumeration<NetworkInterface> getNetworkInterfaces()
throws SocketException {
NetworkInterface[] netifs = getAll();
- assert netifs != null && netifs.length > 0;
-
+ if (netifs != null && netifs.length > 0) {
return enumerationFromArray(netifs);
+ } else {
+ throw new SocketException("Platform Configuration problem,
no network interfaces configured");
+ }
}
/**
@@ -361,15 +365,19 @@
* }</pre>
*
* @return a Stream of NetworkInterfaces found on this machine
- * @exception SocketException if an I/O error occurs.
+ * @exception SocketException if an I/O error occurs,
+ * or if the System does not have at least one configured
+ * network interface.
* @since 9
*/
public static Stream<NetworkInterface> networkInterfaces()
throws SocketException {
NetworkInterface[] netifs = getAll();
- assert netifs != null && netifs.length > 0;
-
+ if (netifs != null && netifs.length > 0) {
return streamFromArray(netifs);
+ } else {
+ throw new SocketException("Platform Configuration problem,
no network interfaces configured");
+ }
}
private static <T> Enumeration<T> enumerationFromArray(T[] a) {