Sonar suggestions - fixes to potential null pointer dereferences

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