diff --git a/common/src/main/java/io/netty/util/NetUtil.java b/common/src/main/java/io/netty/util/NetUtil.java index 97570fa165..88d4cdd015 100644 --- a/common/src/main/java/io/netty/util/NetUtil.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -163,11 +163,14 @@ public final class NetUtil { // Retrieve the list of available network interfaces. List ifaces = new ArrayList(); try { - for (Enumeration i = NetworkInterface.getNetworkInterfaces(); i.hasMoreElements();) { - NetworkInterface iface = i.nextElement(); - // Use the interface with proper INET addresses only. - if (SocketUtils.addressesFromNetworkInterface(iface).hasMoreElements()) { - ifaces.add(iface); + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + if (interfaces != null) { + while (interfaces.hasMoreElements()) { + NetworkInterface iface = interfaces.nextElement(); + // Use the interface with proper INET addresses only. + if (SocketUtils.addressesFromNetworkInterface(iface).hasMoreElements()) { + ifaces.add(iface); + } } } } catch (SocketException e) { diff --git a/common/src/main/java/io/netty/util/internal/MacAddressUtil.java b/common/src/main/java/io/netty/util/internal/MacAddressUtil.java index 4ac088750c..ca4dc75a05 100644 --- a/common/src/main/java/io/netty/util/internal/MacAddressUtil.java +++ b/common/src/main/java/io/netty/util/internal/MacAddressUtil.java @@ -52,14 +52,17 @@ public final class MacAddressUtil { // Retrieve the list of available network interfaces. Map ifaces = new LinkedHashMap(); try { - for (Enumeration i = NetworkInterface.getNetworkInterfaces(); i.hasMoreElements();) { - NetworkInterface iface = i.nextElement(); - // Use the interface with proper INET addresses only. - Enumeration addrs = SocketUtils.addressesFromNetworkInterface(iface); - if (addrs.hasMoreElements()) { - InetAddress a = addrs.nextElement(); - if (!a.isLoopbackAddress()) { - ifaces.put(iface, a); + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + if (interfaces != null) { + while (interfaces.hasMoreElements()) { + NetworkInterface iface = interfaces.nextElement(); + // Use the interface with proper INET addresses only. + Enumeration addrs = SocketUtils.addressesFromNetworkInterface(iface); + if (addrs.hasMoreElements()) { + InetAddress a = addrs.nextElement(); + if (!a.isLoopbackAddress()) { + ifaces.put(iface, a); + } } } }