Fix a few non-null collections 83/57983/2
authorStephen Kitt <skitt@redhat.com>
Mon, 29 May 2017 13:58:39 +0000 (15:58 +0200)
committerSam Hague <shague@redhat.com>
Fri, 2 Jun 2017 00:59:40 +0000 (00:59 +0000)
In general, methods returning collections should never return null.
This patch fixes L2GatewayConnectionUtils and propagates the non-null
results.

Change-Id: If249aec9b8494de736c362f0ea04139151670d68
Signed-off-by: Stephen Kitt <skitt@redhat.com>
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/cli/l2gw/L2GwValidateCli.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/ElanInstanceListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/listeners/HwvtepTerminationPointListener.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2GatewayConnectionUtils.java
vpnservice/elanmanager/elanmanager-impl/src/main/java/org/opendaylight/netvirt/elan/l2gw/utils/L2gwServiceProvider.java

index 37e3fd3c9459db110db294bcbb4c73184c0256eb..b0f2195abde32486f81c07cee0f2dee003f0a980 100644 (file)
@@ -149,10 +149,8 @@ public class L2GwValidateCli extends OsgiCommandSupport {
         }
         l2gatewayConnections = L2GatewayConnectionUtils.getAllL2gatewayConnections(dataBroker);
         l2gateways = L2GatewayConnectionUtils.getL2gatewayList(dataBroker);
-        if (l2gateways != null) {
-            for (L2gateway l2gateway : l2gateways) {
-                uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
-            }
+        for (L2gateway l2gateway : l2gateways) {
+            uuidToL2Gateway.put(l2gateway.getUuid(), l2gateway);
         }
     }
 
index c232e76d5d9862e9324bc3d2d895e57089b7d906..c155a4211d084b41b2d141fa8c831c81d1b2c7bd 100644 (file)
@@ -50,14 +50,12 @@ public class ElanInstanceListener extends AsyncDataTreeChangeListenerBase<ElanIn
         LOG.info("Elan instance {} deleted from Operational tree ", del);
         List<L2gatewayConnection> l2gatewayConnections = L2GatewayConnectionUtils.getL2GwConnectionsByElanName(this
                 .broker, del.getElanInstanceName());
-        if (l2gatewayConnections != null) {
-            LOG.info("L2Gatewconnection {} to be deleted as part of Elan Instance deletion {} ", l2gatewayConnections,
-                    del);
-            for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
-                l2GatewayConnectionUtils.deleteL2GatewayConnection(l2gatewayConnection);
-            }
-            LOG.info("L2Gatewconnection {} delet task submitted Successfully", l2gatewayConnections);
+        LOG.info("L2Gatewconnection {} to be deleted as part of Elan Instance deletion {} ", l2gatewayConnections,
+                del);
+        for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
+            l2GatewayConnectionUtils.deleteL2GatewayConnection(l2gatewayConnection);
         }
+        LOG.info("L2Gatewconnection {} delete task submitted successfully", l2gatewayConnections);
 
     }
 
index e25dd65fad7e6fe259325341d5e967c30ce530b2..e529b2ec7080998d7a06fc987cf77e6d2c0ec480 100644 (file)
@@ -176,15 +176,13 @@ public class HwvtepTerminationPointListener
                 if (isL2GatewayConfigured(l2GwDevice)) {
                     List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(broker,
                             l2GwDevice.getL2GatewayIds());
-                    if (l2GwConns != null) {
-                        String newPortId = portAdded.getTpId().getValue();
-                        NodeId hwvtepNodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
-                        List<VlanBindings> vlanBindings = getVlanBindings(l2GwConns, hwvtepNodeId, psName, newPortId);
-                        List<ListenableFuture<Void>> futures = new ArrayList<>();
-                        futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(hwvtepNodeId, psName,
-                                newPortId, vlanBindings));
-                        return futures;
-                    }
+                    String newPortId = portAdded.getTpId().getValue();
+                    NodeId hwvtepNodeId = new NodeId(l2GwDevice.getHwvtepNodeId());
+                    List<VlanBindings> vlanBindings = getVlanBindings(l2GwConns, hwvtepNodeId, psName, newPortId);
+                    List<ListenableFuture<Void>> futures = new ArrayList<>();
+                    futures.add(elanL2GatewayUtils.updateVlanBindingsInL2GatewayDevice(hwvtepNodeId, psName,
+                            newPortId, vlanBindings));
+                    return futures;
                 }
             } else {
                 LOG.error("{} details are not present in L2Gateway Cache", psName);
index b39cd151eed49fcafcae87604afe864e3a437738..aa4bcb5d1f63757dd2dc828a75190eb12975e277 100644 (file)
@@ -15,9 +15,11 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -84,17 +86,19 @@ public class L2GatewayConnectionUtils {
         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).orNull();
     }
 
+    @Nonnull
     public static List<L2gateway> getL2gatewayList(DataBroker broker) {
         InstanceIdentifier<L2gateways> inst = InstanceIdentifier.create(Neutron.class).child(L2gateways.class);
         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).transform(
-                L2gateways::getL2gateway).orNull();
+                L2gateways::getL2gateway).or(Collections.emptyList());
     }
 
+    @Nonnull
     public static List<L2gatewayConnection> getAllL2gatewayConnections(DataBroker broker) {
         InstanceIdentifier<L2gatewayConnections> inst = InstanceIdentifier.create(Neutron.class)
                 .child(L2gatewayConnections.class);
         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst).transform(
-                L2gatewayConnections::getL2gatewayConnection).orNull();
+                L2gatewayConnections::getL2gatewayConnection).or(Collections.emptyList());
     }
 
     /**
@@ -106,16 +110,14 @@ public class L2GatewayConnectionUtils {
      *            the l2 gateway ids
      * @return the associated l2 gw connections
      */
+    @Nonnull
     public static List<L2gatewayConnection> getAssociatedL2GwConnections(DataBroker broker, Set<Uuid> l2GatewayIds) {
-        List<L2gatewayConnection> l2GwConnections = null;
         List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
-        if (allL2GwConns != null) {
-            l2GwConnections = new ArrayList<>();
-            for (Uuid l2GatewayId : l2GatewayIds) {
-                for (L2gatewayConnection l2GwConn : allL2GwConns) {
-                    if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
-                        l2GwConnections.add(l2GwConn);
-                    }
+        List<L2gatewayConnection> l2GwConnections = new ArrayList<>();
+        for (Uuid l2GatewayId : l2GatewayIds) {
+            for (L2gatewayConnection l2GwConn : allL2GwConns) {
+                if (l2GwConn.getL2gatewayId().equals(l2GatewayId)) {
+                    l2GwConnections.add(l2GwConn);
                 }
             }
         }
@@ -131,14 +133,13 @@ public class L2GatewayConnectionUtils {
      *            the elan Name
      * @return the associated l2 gw connection with elan
      */
+    @Nonnull
     public static List<L2gatewayConnection> getL2GwConnectionsByElanName(DataBroker broker, String elanName) {
         List<L2gatewayConnection> allL2GwConns = getAllL2gatewayConnections(broker);
         List<L2gatewayConnection> elanL2GateWayConnections = new ArrayList<>();
-        if (allL2GwConns != null) {
-            for (L2gatewayConnection l2GwConn : allL2GwConns) {
-                if (l2GwConn.getNetworkId().getValue().equalsIgnoreCase(elanName)) {
-                    elanL2GateWayConnections.add(l2GwConn);
-                }
+        for (L2gatewayConnection l2GwConn : allL2GwConns) {
+            if (l2GwConn.getNetworkId().getValue().equalsIgnoreCase(elanName)) {
+                elanL2GateWayConnections.add(l2GwConn);
             }
         }
         return elanL2GateWayConnections;
index d21bf1a9fa98ce6faceba31b4afb6a23bb2c27e4..a16535d90d5651d91b035d85e57c5c53a8141cf0 100644 (file)
@@ -54,13 +54,11 @@ public class L2gwServiceProvider extends AbstractLifecycle implements IL2gwServi
 
         List<L2gatewayConnection> l2GwConns = L2GatewayConnectionUtils.getAssociatedL2GwConnections(
                 dataBroker, l2GwDevice.getL2GatewayIds());
-        if (l2GwConns != null) {
-            LOG.debug("L2GatewayConnections associated for {} physical switch", psName);
-            for (L2gatewayConnection l2GwConn : l2GwConns) {
-                LOG.trace("L2GatewayConnection {} changes executed on physical switch {}",
-                        l2GwConn.getL2gatewayId(), psName);
-                elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(l2GwConn, psName);
-            }
+        LOG.debug("L2GatewayConnections associated for {} physical switch", psName);
+        for (L2gatewayConnection l2GwConn : l2GwConns) {
+            LOG.trace("L2GatewayConnection {} changes executed on physical switch {}",
+                    l2GwConn.getL2gatewayId(), psName);
+            elanUtils.getL2GatewayConnectionUtils().addL2GatewayConnection(l2GwConn, psName);
         }
     }