Handle nullable lists in elanmanager
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / commands / LocalMcastCmd.java
index 962e65f00e6aee794c454df7c2a42ed4d7f240d6..913dd6bc83f420fb7f0023b165a087fa8d3c24f9 100644 (file)
@@ -7,8 +7,13 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
 
+import static org.opendaylight.netvirt.elan.utils.ElanUtils.requireNonNullElse;
+
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
+import javax.annotation.Nullable;
 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
@@ -31,6 +36,7 @@ public class LocalMcastCmd
     }
 
     @Override
+    @Nullable
     public List<LocalMcastMacs> getData(HwvtepGlobalAugmentation node) {
         if (node != null) {
             return node.getLocalMcastMacs();
@@ -55,7 +61,7 @@ public class LocalMcastCmd
     public LocalMcastMacs transform(InstanceIdentifier<Node> nodePath, LocalMcastMacs src) {
         LocalMcastMacsBuilder ucmlBuilder = new LocalMcastMacsBuilder(src);
         List<LocatorSet> locatorSet = new ArrayList<>();
-        for (LocatorSet locator : src.getLocatorSet()) {
+        for (LocatorSet locator : requireNonNullElse(src.getLocatorSet(), Collections.<LocatorSet>emptyList())) {
             locatorSet.add(new LocatorSetBuilder().setLocatorRef(HwvtepHAUtil.buildLocatorRef(nodePath,
                     HwvtepHAUtil.getTepIpVal(locator.getLocatorRef()))).build());
         }
@@ -86,7 +92,7 @@ public class LocalMcastCmd
                 .getHwvtepNodeName();
         InstanceIdentifier<?> origMacRefIdentifier = orig.getLogicalSwitchRef().getValue();
         HwvtepNodeName origMacNodeName = origMacRefIdentifier.firstKeyOf(LogicalSwitches.class).getHwvtepNodeName();
-        if (updated.getMacEntryKey().equals(orig.getMacEntryKey())
+        if (Objects.equals(updated.getMacEntryKey(), orig.getMacEntryKey())
                 && updatedMacNodeName.equals(origMacNodeName)) {
             List<LocatorSet> updatedLocatorSet = updated.getLocatorSet();
             List<LocatorSet> origLocatorSet = orig.getLocatorSet();