Sonar suggestions - fixes to potential null pointer dereferences

Change-Id: I4e350a9d72a9322971d5d4f831f1bdf167986b87
diff --git a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java
index 890c7ba..b0efe80 100644
--- a/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java
+++ b/apps/actn-mdsc/tetunnel-pce/src/main/java/org/onosproject/actn/mdsc/pce/impl/TeTunnelPceManager.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.actn.mdsc.pce.impl;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -63,7 +64,11 @@
                 }
             }
         }
-        return pce.computePaths(teTunnel);
+        if (pce != null) {
+            return pce.computePaths(teTunnel);
+        } else {
+            return ImmutableList.of();
+        }
     }
 
     @Override
diff --git a/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java b/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
index ca10f86..dc7ea22 100644
--- a/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
+++ b/apps/cpman/app/src/main/java/org/onosproject/cpman/rest/SystemMetricsCollectorWebResource.java
@@ -93,7 +93,7 @@
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
 
             if (jsonTree == null || !checkFields(jsonTree, CPU_FIELD_SET)) {
-                ok(root).build();
+                return ok(root).build();
             }
 
             long cpuLoad = nullIsIllegal((long) (jsonTree.get("cpuLoad").asDouble()
@@ -154,7 +154,7 @@
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
 
             if (jsonTree == null || !checkFields(jsonTree, MEMORY_FIELD_SET)) {
-                ok(root).build();
+                return ok(root).build();
             }
 
             long memUsed = nullIsIllegal(jsonTree.get("memoryUsed").asLong(), INVALID_REQUEST);
diff --git a/apps/linkprops/src/main/java/org/onosproject/linkprops/LinkPropsTopovMessageHandler.java b/apps/linkprops/src/main/java/org/onosproject/linkprops/LinkPropsTopovMessageHandler.java
index 908c65c..a633ec0 100644
--- a/apps/linkprops/src/main/java/org/onosproject/linkprops/LinkPropsTopovMessageHandler.java
+++ b/apps/linkprops/src/main/java/org/onosproject/linkprops/LinkPropsTopovMessageHandler.java
@@ -248,27 +248,26 @@
      */
     private Highlights getBandwidth(Set<Link> links, DeviceId devId) {
         LpLinkMap linkMap = new LpLinkMap();
+        Highlights highlights = new Highlights();
         if (links != null) {
             log.debug("Processing {} links", links.size());
             links.forEach(linkMap::add);
+
+            PortNumber portnum = PortNumber.portNumber((int) links.iterator().next().src().port().toLong());
+
+            for (LpLink dlink : linkMap.biLinks()) {
+                DiscreteResourceId parent = Resources.discrete(devId, portnum).id();
+                ContinuousResource continuousResource =
+                        (ContinuousResource) resourceQueryService.getAvailableResources(parent,
+                                Bandwidth.class).iterator().next();
+                double availBandwidth = continuousResource.value();
+
+                dlink.makeImportant().setLabel(Double.toString(availBandwidth) + " bytes/s");
+                highlights.add(dlink.highlight(null));
+            }
         } else {
             log.debug("No egress links found for device {}", devId);
         }
-
-        Highlights highlights = new Highlights();
-
-        PortNumber portnum = PortNumber.portNumber((int) links.iterator().next().src().port().toLong());
-
-        for (LpLink dlink : linkMap.biLinks()) {
-            DiscreteResourceId parent = Resources.discrete(devId, portnum).id();
-            ContinuousResource continuousResource =
-                    (ContinuousResource) resourceQueryService.getAvailableResources(parent,
-                                                                                    Bandwidth.class).iterator().next();
-            double availBandwidth = continuousResource.value();
-
-            dlink.makeImportant().setLabel(Double.toString(availBandwidth) + " bytes/s");
-            highlights.add(dlink.highlight(null));
-        }
         return highlights;
     }
 
diff --git a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/impl/RulePopulatorUtil.java b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/impl/RulePopulatorUtil.java
index b569da1..128bf7b 100644
--- a/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/impl/RulePopulatorUtil.java
+++ b/apps/openstacknetworking/src/main/java/org/onosproject/openstacknetworking/impl/RulePopulatorUtil.java
@@ -98,6 +98,10 @@
             return null;
         }
 
+        if (device == null) {
+            return null;
+        }
+
         ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
         ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
         try {
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
index e1da821..625d41d 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
@@ -474,6 +474,10 @@
             return null;
         }
 
+        if (device == null) {
+            return null;
+        }
+
         ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
         ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
         try {
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/config/OpticalPortOperator.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/config/OpticalPortOperator.java
index f9ee752..ee5ac99 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/config/OpticalPortOperator.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/config/OpticalPortOperator.java
@@ -93,7 +93,7 @@
         }
 
         OpticalPortConfig opc = lookupConfig(cp);
-        if (opc == null) {
+        if (descr == null || opc == null) {
             return descr;
         }
 
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
index 47c369c..41d54c2 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/PceManager.java
@@ -610,10 +610,7 @@
             return false;
         }
 
-        DisjointPath path = null;
-        if (!paths.isEmpty()) {
-            path = paths.iterator().next();
-        }
+        DisjointPath path = paths.iterator().next();
 
         Builder annotationBuilder = DefaultAnnotations.builder();
         double bw = 0;
diff --git a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
index 5b6ad9c..906e34d 100644
--- a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
+++ b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
@@ -263,8 +263,10 @@
         case HOST_TO_INTERNET:
             // If the destination IP address is outside the local SDN network.
             // The Step 1 has already handled it. We do not need to do anything here.
-            intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress,
-                    ipPrefix, route.nextHop());
+            if (route != null) {
+                intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress,
+                        ipPrefix, route.nextHop());
+            }
             break;
         case INTERNET_TO_HOST:
             intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
diff --git a/apps/restconf/restconfmgr/src/main/java/org/onosproject/restconf/restconfmanager/RestconfManager.java b/apps/restconf/restconfmgr/src/main/java/org/onosproject/restconf/restconfmanager/RestconfManager.java
index 356306d..e495a57 100644
--- a/apps/restconf/restconfmgr/src/main/java/org/onosproject/restconf/restconfmanager/RestconfManager.java
+++ b/apps/restconf/restconfmgr/src/main/java/org/onosproject/restconf/restconfmanager/RestconfManager.java
@@ -311,7 +311,8 @@
             }
             parentId = rid.copyBuilder().removeLastKey().build();
         } catch (CloneNotSupportedException e) {
-            e.printStackTrace();
+            log.error("getDataForStore()", e);
+            return null;
         }
         ResourceData.Builder resData = DefaultResourceData.builder();
         resData.addDataNode(dbr.build());
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentRemoveCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentRemoveCommand.java
index 4ead980..cadae7e 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentRemoveCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentRemoveCommand.java
@@ -214,7 +214,7 @@
                     if (event.type() == IntentEvent.Type.WITHDRAWN ||
                             event.type() == IntentEvent.Type.FAILED) {
                         withdrawLatch.countDown();
-                    } else if (purgeAfterRemove &&
+                    } else if (purgeLatch != null && purgeAfterRemove &&
                             event.type() == IntentEvent.Type.PURGED) {
                         purgeLatch.countDown();
                     }
@@ -229,13 +229,13 @@
         // request the withdraw
         intentService.withdraw(intent);
 
-        if (purgeAfterRemove || sync) {
+        if (withdrawLatch != null && (purgeAfterRemove || sync)) {
             try { // wait for withdraw event
                 withdrawLatch.await(5, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
                 print("Timed out waiting for intent {} withdraw", key);
             }
-            if (purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
+            if (purgeLatch != null && purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
                 intentService.purge(intent);
                 if (sync) { // wait for purge event
                     /* TODO
diff --git a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualNetworkIntentRemoveCommand.java b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualNetworkIntentRemoveCommand.java
index 8f073e6..7ba6791 100644
--- a/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualNetworkIntentRemoveCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/vnet/VirtualNetworkIntentRemoveCommand.java
@@ -140,7 +140,7 @@
                     if (event.type() == IntentEvent.Type.WITHDRAWN ||
                             event.type() == IntentEvent.Type.FAILED) {
                         withdrawLatch.countDown();
-                    } else if (purgeAfterRemove &&
+                    } else if (purgeLatch != null && purgeAfterRemove &&
                             event.type() == IntentEvent.Type.PURGED) {
                         purgeLatch.countDown();
                     }
@@ -155,7 +155,7 @@
         // request the withdraw
         intentService.withdraw(intent);
 
-        if (purgeAfterRemove || sync) {
+        if ((purgeAfterRemove || sync) && purgeLatch != null) {
             try { // wait for withdraw event
                 withdrawLatch.await(5, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
diff --git a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
index bd3e65e..c205345 100644
--- a/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
+++ b/core/api/src/main/java/org/onosproject/cluster/ClusterMetadata.java
@@ -17,6 +17,7 @@
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -140,17 +141,19 @@
     @Override
     public boolean equals(Object object) {
 
+        if (object == null) {
+            return false;
+        }
+
         if (!ClusterMetadata.class.isInstance(object)) {
             return false;
         }
         ClusterMetadata that = (ClusterMetadata) object;
 
-        if (!this.name.equals(that.name) || this.nodes.size() != that.nodes.size()
-                || this.partitions.size() != that.partitions.size()) {
-            return false;
-        }
-
-        return Sets.symmetricDifference(this.nodes, that.nodes).isEmpty()
-                && Sets.symmetricDifference(this.partitions, that.partitions).isEmpty();
+        return Objects.equals(this.name, that.name) &&
+               Objects.equals(this.nodes.size(), that.nodes.size()) &&
+               Objects.equals(this.partitions.size(), that.partitions.size()) &&
+               Sets.symmetricDifference(this.nodes, that.nodes).isEmpty() &&
+               Sets.symmetricDifference(this.partitions, that.partitions).isEmpty();
     }
 }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/util/IntentFilter.java b/core/api/src/main/java/org/onosproject/net/intent/util/IntentFilter.java
index 99b887f..24be4ef 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/util/IntentFilter.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/util/IntentFilter.java
@@ -132,18 +132,18 @@
 
             if (objective instanceof NextObjective) {
                 nextObjective = (DefaultNextObjective) objective;
-                continue;
-
             } else if (objective instanceof ForwardingObjective) {
                 forwardObjective = (DefaultForwardingObjective) objective;
-                FlowRule flowRule = DefaultFlowRule.builder()
+                FlowRule.Builder builder = DefaultFlowRule.builder()
                         .forDevice(deviceId)
                         .withSelector(forwardObjective.selector())
-                        .withTreatment(nextObjective.next().iterator().next())
                         .withPriority(intent.priority())
                         .fromApp(intent.appId())
-                        .makePermanent()
-                        .build();
+                        .makePermanent();
+                if (nextObjective != null) {
+                    builder.withTreatment(nextObjective.next().iterator().next());
+                }
+                FlowRule flowRule = builder.build();
                 flowEntry = getFlowEntry(flowRule);
 
                 if (flowEntry != null) {
diff --git a/core/store/dist/src/main/java/org/onosproject/store/app/DistributedApplicationStore.java b/core/store/dist/src/main/java/org/onosproject/store/app/DistributedApplicationStore.java
index d9e3bf3..fd6826a 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/app/DistributedApplicationStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/app/DistributedApplicationStore.java
@@ -464,6 +464,9 @@
             ApplicationId appId = event.key();
             InternalApplicationHolder newApp = event.newValue() == null ? null : event.newValue().value();
             InternalApplicationHolder oldApp = event.oldValue() == null ? null : event.oldValue().value();
+            if (newApp == null || oldApp == null) {
+                return;
+            }
             if (event.type() == MapEvent.Type.INSERT || event.type() == MapEvent.Type.UPDATE) {
                 if (event.type() == MapEvent.Type.UPDATE && newApp.state() == oldApp.state()) {
                     return;
diff --git a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
index dcf58e6..9cf9856 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/host/impl/DistributedHostStore.java
@@ -477,7 +477,7 @@
             }
         }
 
-        if (existingHosts.isEmpty()) {
+        if (existingHosts == null || existingHosts.isEmpty()) {
             return null;
         }
         return existingHosts;
diff --git a/drivers/ciena/src/main/java/org/onosproject/drivers/ciena/CienaWaveserverDeviceDescription.java b/drivers/ciena/src/main/java/org/onosproject/drivers/ciena/CienaWaveserverDeviceDescription.java
index 3918c02..c0ef3a9 100644
--- a/drivers/ciena/src/main/java/org/onosproject/drivers/ciena/CienaWaveserverDeviceDescription.java
+++ b/drivers/ciena/src/main/java/org/onosproject/drivers/ciena/CienaWaveserverDeviceDescription.java
@@ -162,7 +162,8 @@
 
         //Working in Ghz //(Nominal central frequency - 193.1)/channelSpacing = spacingMultiplier
         final int baseFrequency = 193100;
-        int spacingMult = (int) (toGbps(((int) config.getDouble(frequency) -
+
+        int spacingMult = chSpacing == null ? baseFrequency : (int) (toGbps(((int) config.getDouble(frequency) -
                 baseFrequency)) / toGbpsFromHz(chSpacing.frequency().asHz())); //FIXME is there a better way ?
 
         return ochPortDescription(PortNumber.portNumber(portNumber), isEnabled, OduSignalType.ODU4, isTunable,
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java
index 6c73693..ef79ee3 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java
@@ -381,7 +381,8 @@
             return;
         }
 
-        EthCriterion e = null; VlanIdCriterion v = null;
+        EthCriterion e = null;
+        VlanIdCriterion v = null;
         Collection<IPCriterion> ips = new ArrayList<IPCriterion>();
         // convert filtering conditions for switch-intfs into flowrules
         FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
@@ -399,6 +400,12 @@
             }
         }
 
+        if (v == null || e == null) {
+            log.warn("Pica Pipeline ETH_DST and/or VLAN_ID not specified");
+            fail(filt, ObjectiveError.BADPARAMS);
+            return;
+        }
+
         // cache for later use
         Filter filter = new Filter(p, e, v, ips);
         filters.add(filter);
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
index 03a77ba..9ca9420 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java
@@ -270,6 +270,12 @@
 
         }
 
+        if (v == null || e == null) {
+            log.warn("Soft Router Pipeline ETH_DST and/or VLAN_ID not specified");
+            fail(filt, ObjectiveError.BADPARAMS);
+            return;
+        }
+
         log.debug("Modifying Port/VLAN/MAC filtering rules in filter table: {}/{}/{}",
                   p.port(), v.vlanId(), e.mac());
         TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2Pipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2Pipeline.java
index c5698a4..d8de983 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2Pipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2Pipeline.java
@@ -336,14 +336,16 @@
         // ofdpa cannot match on ALL portnumber, so we need to use separate
         // rules for each port.
         List<PortNumber> portnums = new ArrayList<PortNumber>();
-        if (portCriterion.port() == PortNumber.ALL) {
-            for (Port port : deviceService.getPorts(deviceId)) {
-                if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
-                    portnums.add(port.number());
+        if (portCriterion != null) {
+            if (portCriterion.port() == PortNumber.ALL) {
+                for (Port port : deviceService.getPorts(deviceId)) {
+                    if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
+                        portnums.add(port.number());
+                    }
                 }
+            } else {
+                portnums.add(portCriterion.port());
             }
-        } else {
-            portnums.add(portCriterion.port());
         }
 
         List<FlowRule> rules = new ArrayList<FlowRule>();
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2VlanPipeline.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2VlanPipeline.java
index 701b76e..0279cb1 100644
--- a/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2VlanPipeline.java
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/ofdpa/CpqdOfdpa2VlanPipeline.java
@@ -108,14 +108,16 @@
         // ofdpa cannot match on ALL portnumber, so we need to use separate
         // rules for each port.
         List<PortNumber> portnums = new ArrayList<PortNumber>();
-        if (portCriterion.port() == PortNumber.ALL) {
-            for (Port port : deviceService.getPorts(deviceId)) {
-                if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
-                    portnums.add(port.number());
+        if (portCriterion != null) {
+            if (portCriterion.port() == PortNumber.ALL) {
+                for (Port port : deviceService.getPorts(deviceId)) {
+                    if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) {
+                        portnums.add(port.number());
+                    }
                 }
+            } else {
+                portnums.add(portCriterion.port());
             }
-        } else {
-            portnums.add(portCriterion.port());
         }
 
         List<FlowRule> rules = new ArrayList<FlowRule>();
diff --git a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfig.java b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfig.java
index 2431d2d..173b58e 100644
--- a/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfig.java
+++ b/drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltControllerConfig.java
@@ -213,13 +213,13 @@
         try {
              editcfg = (XMLConfiguration) cfg;
         } catch (ClassCastException e) {
-            e.printStackTrace();
+            return null;
         }
         StringWriter stringWriter = new StringWriter();
         try {
             editcfg.save(stringWriter);
         } catch (ConfigurationException e) {
-            e.printStackTrace();
+            return null;
         }
         String s = stringWriter.toString();
         String fromStr = buildStartTag(TARGET, false) + target +
diff --git a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
index bce3b6d..f094ba1 100644
--- a/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
+++ b/drivers/netconf/src/main/java/org/onosproject/drivers/netconf/NetconfControllerConfig.java
@@ -97,6 +97,7 @@
                     );
                 } catch (IOException e) {
                     log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
+                    return;
                 }
                 device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
             } catch (NullPointerException e) {
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
index 106c4bb..578f4fe 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
@@ -447,7 +447,7 @@
             if (listIterator.hasNext()) {
                 tlv1 = listIterator.next();
             }
-            while (listIterator.hasNext()) {
+            while (tlv1 != null && listIterator.hasNext()) {
                 BgpValueType tlv = listIterator.next();
                 if (tlv.getType() != tlv1.getType()) {
                     isAllFlowTypesIdentical = false;
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
index e06fb0a..ac63ba7 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -402,7 +402,7 @@
             if (listIterator.hasNext()) {
                 tlv1 = listIterator.next();
             }
-            while (listIterator.hasNext()) {
+            while (tlv1 != null && listIterator.hasNext()) {
                 BgpValueType tlv = listIterator.next();
                 if (tlv.getType() != tlv1.getType()) {
                     isAllFlowTypesIdentical = false;
diff --git a/protocols/pcep/server/ctl/src/main/java/org/onosproject/pcep/server/impl/PcepClientControllerImpl.java b/protocols/pcep/server/ctl/src/main/java/org/onosproject/pcep/server/impl/PcepClientControllerImpl.java
index 2ddc819..1bb5610 100644
--- a/protocols/pcep/server/ctl/src/main/java/org/onosproject/pcep/server/impl/PcepClientControllerImpl.java
+++ b/protocols/pcep/server/ctl/src/main/java/org/onosproject/pcep/server/impl/PcepClientControllerImpl.java
@@ -1005,6 +1005,10 @@
                     }
                 }
 
+                if (ipv4LspIdenTlv == null) {
+                    return false;
+                }
+
                 LspKey lspKeyOfRpt = new LspKey(lspObj.getPlspId(), ipv4LspIdenTlv.getLspId());
                 tunnel = preSyncLspDbByKey.get(lspKeyOfRpt);
                 // PCE tunnel is matched with PCRpt LSP. Now delete it from the preSyncLspDb list as the residual
@@ -1059,7 +1063,8 @@
                 // State different for PCC sent LSP and PCE known LSP, send PCUpd msg.
                 State tunnelState = PcepLspStatus
                         .getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
-                if (tunnelState != tunnel.state()) {
+
+                if (tunnel != null && tunnelState != tunnel.state()) {
                     for (PcepEventListener l : pcepEventListener) {
                         l.handleEndOfSyncAction(tunnel, SEND_UPDATE);
                     }
diff --git a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
index eadb4cf..0633d12 100644
--- a/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
+++ b/providers/host/src/main/java/org/onosproject/provider/host/impl/HostLocationProvider.java
@@ -418,6 +418,7 @@
             // IPv6: Use Neighbor Discovery
             //TODO need to implement ndp probe
             log.info("Triggering probe on device {} ", host);
+            return;
         }
 
         TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(host.location().port()).build();
diff --git a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
index a2d21bc..664aaa4 100644
--- a/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
+++ b/providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/PcepTunnelProvider.java
@@ -1609,7 +1609,7 @@
             DefaultTunnelDescription td;
             SparseAnnotations annotations = null;
             State tunnelState = PcepLspStatus.getTunnelStatusFromLspStatus(PcepLspStatus.values()[lspObj.getOFlag()]);
-            if (tunnel == null) {
+            if (tunnel == null && pathNameTlv != null) {
                 if (lspObj.getRFlag()) {
                     /*
                      * If PCC sends remove message and for any reason PCE does not have that entry, simply discard the
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
index 4f186ef..e6f7e9c 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowObjectiveWebResource.java
@@ -75,22 +75,22 @@
         try {
             UriBuilder locationBuilder = null;
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-            if (validateDeviceId(deviceId, jsonTree)) {
+            validateDeviceId(deviceId, jsonTree);
 
-                if (appId != null) {
-                    jsonTree.put("appId", appId);
-                }
-
-                DeviceId did = DeviceId.deviceId(deviceId);
-                FilteringObjective filteringObjective =
-                        codec(FilteringObjective.class).decode(jsonTree, this);
-                flowObjectiveService.filter(did, filteringObjective);
-                locationBuilder = uriInfo.getBaseUriBuilder()
-                        .path("flowobjectives")
-                        .path(did.toString())
-                        .path("filter")
-                        .path(Integer.toString(filteringObjective.id()));
+            if (appId != null) {
+                jsonTree.put("appId", appId);
             }
+
+            DeviceId did = DeviceId.deviceId(deviceId);
+            FilteringObjective filteringObjective =
+                    codec(FilteringObjective.class).decode(jsonTree, this);
+            flowObjectiveService.filter(did, filteringObjective);
+            locationBuilder = uriInfo.getBaseUriBuilder()
+                    .path("flowobjectives")
+                    .path(did.toString())
+                    .path("filter")
+                    .path(Integer.toString(filteringObjective.id()));
+
             return Response
                     .created(locationBuilder.build())
                     .build();
@@ -119,22 +119,22 @@
         try {
             UriBuilder locationBuilder = null;
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-            if (validateDeviceId(deviceId, jsonTree)) {
+            validateDeviceId(deviceId, jsonTree);
 
-                if (appId != null) {
-                    jsonTree.put("appId", appId);
-                }
-
-                DeviceId did = DeviceId.deviceId(deviceId);
-                ForwardingObjective forwardingObjective =
-                        codec(ForwardingObjective.class).decode(jsonTree, this);
-                flowObjectiveService.forward(did, forwardingObjective);
-                locationBuilder = uriInfo.getBaseUriBuilder()
-                        .path("flowobjectives")
-                        .path(did.toString())
-                        .path("forward")
-                        .path(Integer.toString(forwardingObjective.id()));
+            if (appId != null) {
+                jsonTree.put("appId", appId);
             }
+
+            DeviceId did = DeviceId.deviceId(deviceId);
+            ForwardingObjective forwardingObjective =
+                    codec(ForwardingObjective.class).decode(jsonTree, this);
+            flowObjectiveService.forward(did, forwardingObjective);
+            locationBuilder = uriInfo.getBaseUriBuilder()
+                    .path("flowobjectives")
+                    .path(did.toString())
+                    .path("forward")
+                    .path(Integer.toString(forwardingObjective.id()));
+
             return Response
                     .created(locationBuilder.build())
                     .build();
@@ -163,22 +163,22 @@
         try {
             UriBuilder locationBuilder = null;
             ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-            if (validateDeviceId(deviceId, jsonTree)) {
+            validateDeviceId(deviceId, jsonTree);
 
-                if (appId != null) {
-                    jsonTree.put("appId", appId);
-                }
-
-                DeviceId did = DeviceId.deviceId(deviceId);
-                NextObjective nextObjective =
-                        codec(NextObjective.class).decode(jsonTree, this);
-                flowObjectiveService.next(did, nextObjective);
-                locationBuilder = uriInfo.getBaseUriBuilder()
-                        .path("flowobjectives")
-                        .path(did.toString())
-                        .path("next")
-                        .path(Integer.toString(nextObjective.id()));
+            if (appId != null) {
+                jsonTree.put("appId", appId);
             }
+
+            DeviceId did = DeviceId.deviceId(deviceId);
+            NextObjective nextObjective =
+                    codec(NextObjective.class).decode(jsonTree, this);
+            flowObjectiveService.next(did, nextObjective);
+            locationBuilder = uriInfo.getBaseUriBuilder()
+                    .path("flowobjectives")
+                    .path(did.toString())
+                    .path("next")
+                    .path(Integer.toString(nextObjective.id()));
+
             return Response
                     .created(locationBuilder.build())
                     .build();
@@ -234,15 +234,14 @@
      *
      * @param deviceId device identifier
      * @param node     object node
-     * @return validity
+     * @throws IllegalArgumentException if the device id is invalid
      */
-    private boolean validateDeviceId(String deviceId, ObjectNode node) {
+    private void validateDeviceId(String deviceId, ObjectNode node) {
         JsonNode specifiedDeviceId = node.get("deviceId");
 
         if (specifiedDeviceId != null &&
                 !specifiedDeviceId.asText().equals(deviceId)) {
             throw new IllegalArgumentException(DEVICE_INVALID);
         }
-        return true;
     }
 }