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) {