cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [cxf] branch master updated: Guard against null return value from (#720)
Date Fri, 06 Nov 2020 08:39:32 GMT
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d27850  Guard against null return value from (#720)
2d27850 is described below

commit 2d2785078a4ee1133d81b932d4f68e0adfa78077
Author: Gary Gregory <garydgregory@users.noreply.github.com>
AuthorDate: Fri Nov 6 03:39:18 2020 -0500

    Guard against null return value from (#720)
    
    java.net.NetworkInterface.getNetworkInterfaces().
---
 .../apache/cxf/transport/udp/UDPDestination.java   | 23 ++++++++---------
 .../apache/cxf/transport/udp/UDPTransportTest.java | 12 +++++----
 .../cxf/ws/discovery/WSDiscoveryClientTest.java    | 30 ++++++++++++----------
 3 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
index b0c8254..3b5d08d 100644
--- a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
+++ b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
@@ -196,22 +196,21 @@ public class UDPDestination extends AbstractDestination {
         }
         if (ret == null) {
             Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
-            List<NetworkInterface> possibles = new ArrayList<>();
-            while (ifcs.hasMoreElements()) {
-                NetworkInterface ni = ifcs.nextElement();
-                if (ni.supportsMulticast()
-                    && ni.isUp()) {
-                    for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
-                        if (ia.getAddress() instanceof java.net.Inet4Address
-                            && !ia.getAddress().isLoopbackAddress()
-                            && !ni.getDisplayName().startsWith("vnic")) {
-                            possibles.add(ni);
+            if (ifcs != null) {
+                List<NetworkInterface> possibles = new ArrayList<>();
+                while (ifcs.hasMoreElements()) {
+                    NetworkInterface ni = ifcs.nextElement();
+                    if (ni.supportsMulticast() && ni.isUp()) {
+                        for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
+                            if (ia.getAddress() instanceof java.net.Inet4Address &&
!ia.getAddress().isLoopbackAddress()
+                                    && !ni.getDisplayName().startsWith("vnic")) {
+                                possibles.add(ni);
+                            }
                         }
                     }
                 }
+                ret = possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
             }
-            ret = possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
-
         }
         return ret;
     }
diff --git a/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
b/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
index dccb735..712c8fc 100644
--- a/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
+++ b/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
@@ -102,12 +102,14 @@ public class UDPTransportTest {
 
         Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
         int count = 0;
-        while (interfaces.hasMoreElements()) {
-            NetworkInterface networkInterface = interfaces.nextElement();
-            if (!networkInterface.isUp() || networkInterface.isLoopback()) {
-                continue;
+        if (interfaces != null) {
+            while (interfaces.hasMoreElements()) {
+                NetworkInterface networkInterface = interfaces.nextElement();
+                if (!networkInterface.isUp() || networkInterface.isLoopback()) {
+                    continue;
+                }
+                count++;
             }
-            count++;
         }
         if (count == 0) {
             //no non-loopbacks, cannot do broadcasts
diff --git a/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
b/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
index 17df37b..b8a3138 100644
--- a/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
+++ b/services/ws-discovery/ws-discovery-api/src/test/java/org/apache/cxf/ws/discovery/WSDiscoveryClientTest.java
@@ -61,15 +61,15 @@ public final class WSDiscoveryClientTest {
     static NetworkInterface findIpv4Interface() throws Exception {
         Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
         List<NetworkInterface> possibles = new ArrayList<>();
-        while (ifcs.hasMoreElements()) {
-            NetworkInterface ni = ifcs.nextElement();
-            if (ni.supportsMulticast()
-                && ni.isUp()) {
-                for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
-                    if (ia.getAddress() instanceof java.net.Inet4Address
-                        && !ia.getAddress().isLoopbackAddress()
-                        && !ni.getDisplayName().startsWith("vnic")) {
-                        possibles.add(ni);
+        if (ifcs != null) {
+            while (ifcs.hasMoreElements()) {
+                NetworkInterface ni = ifcs.nextElement();
+                if (ni.supportsMulticast() && ni.isUp()) {
+                    for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
+                        if (ia.getAddress() instanceof java.net.Inet4Address && !ia.getAddress().isLoopbackAddress()
+                                && !ni.getDisplayName().startsWith("vnic")) {
+                            possibles.add(ni);
+                        }
                     }
                 }
             }
@@ -88,12 +88,14 @@ public final class WSDiscoveryClientTest {
 
         Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
         int count = 0;
-        while (interfaces.hasMoreElements()) {
-            NetworkInterface networkInterface = interfaces.nextElement();
-            if (!networkInterface.isUp() || networkInterface.isLoopback()) {
-                continue;
+        if (interfaces != null) {
+            while (interfaces.hasMoreElements()) {
+                NetworkInterface networkInterface = interfaces.nextElement();
+                if (!networkInterface.isUp() || networkInterface.isLoopback()) {
+                    continue;
+                }
+                count++;
             }
-            count++;
         }
         if (count == 0) {
             //no non-loopbacks, cannot do broadcasts


Mime
View raw message