Handle nullable lists in natservice
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / NatInterfaceStateChangeListener.java
index 49567a129cac74c5dccc4a6426a3ee284bf720a2..7fbcf0354478fc91f1b59bb7caedd8f1966f0e91 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.netvirt.natservice.internal;
 
+import static org.opendaylight.netvirt.natservice.internal.NatUtil.requireNonNullElse;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 
+import java.util.Collections;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -116,7 +119,8 @@ public class NatInterfaceStateChangeListener
                 LOG.warn("remove : Interface {} is not a VPN Interface, ignoring.", interfaceName);
                 return;
             }
-            for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
+            for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+                    cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
                 String vpnName  = vpnInterfaceVpnInstance.getVpnName();
                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
@@ -129,7 +133,7 @@ public class NatInterfaceStateChangeListener
                 }
             }
         }
-        if (intfDpnId.equals(BigInteger.ZERO)) {
+        if (BigInteger.ZERO.equals(intfDpnId)) {
             LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
             return;
         }
@@ -164,7 +168,8 @@ public class NatInterfaceStateChangeListener
                 LOG.warn("update : Interface {} is not a VPN Interface, ignoring.", interfaceName);
                 return;
             }
-            for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
+            for (VpnInstanceNames vpnInterfaceVpnInstance : requireNonNullElse(
+                    cfgVpnInterface.get().getVpnInstanceNames(), Collections.<VpnInstanceNames>emptyList())) {
                 String vpnName  = vpnInterfaceVpnInstance.getVpnName();
                 InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = NatUtil
                       .getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
@@ -177,7 +182,7 @@ public class NatInterfaceStateChangeListener
                 }
             }
         }
-        if (intfDpnId.equals(BigInteger.ZERO)) {
+        if (BigInteger.ZERO.equals(intfDpnId)) {
             LOG.warn("remove : Could not retrieve dpnid for interface {} ", interfaceName);
             return;
         }