Fix for ONOS-5323:Issue with POST /intents - Causing NPE with null/wrong appId

Change-Id: I50e952976a0f8628ab2f4769b10ac1b3e1f152b6
(cherry picked from commit 3a0820beb627a3594411e43c97d025247fc69faa)
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
index a51665b..11429d4 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
@@ -32,6 +32,7 @@
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onlab.util.Tools.nullIsIllegal;
+import static org.onlab.util.Tools.nullIsNotFound;
 
 /**
  * Intent JSON codec.
@@ -46,6 +47,8 @@
     protected static final String RESOURCES = "resources";
     protected static final String MISSING_MEMBER_MESSAGE =
             " member is required in Intent";
+    private static final String E_APP_ID_NOT_FOUND =
+            "Application ID is not found";
 
     @Override
     public ObjectNode encode(Intent intent, CodecContext context) {
@@ -104,7 +107,7 @@
         String appId = nullIsIllegal(json.get(IntentCodec.APP_ID),
                 IntentCodec.APP_ID + IntentCodec.MISSING_MEMBER_MESSAGE).asText();
         CoreService service = context.getService(CoreService.class);
-        builder.appId(service.getAppId(appId));
+        builder.appId(nullIsNotFound(service.getAppId(appId), IntentCodec.E_APP_ID_NOT_FOUND));
 
         JsonNode priorityJson = json.get(IntentCodec.PRIORITY);
         if (priorityJson != null) {