Sonar suggestions - fixes to potential null pointer dereferences

Change-Id: I4e350a9d72a9322971d5d4f831f1bdf167986b87
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;