From 8202525d2e4ede3754b1b48c560bce8493aff281 Mon Sep 17 00:00:00 2001
From: "r.bogacki" <r.bogacki@samsung.com>
Date: Mon, 6 May 2019 09:25:02 +0200
Subject: Fixed NPE in ResourceRequestBuilder

Fixed possible NullPointerException in ResourceRequestBuilder
according to the Sonar analysis.

Change-Id: Ide97a1a6439342ef55fc490916c945d194d4e518
Issue-ID: SO-1498
Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
---
 .../so/bpmn/common/resource/ResourceRequestBuilder.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'bpmn/MSOCommonBPMN/src/main/java/org/onap')

diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
index 58f775ce0b..0df25be714 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
@@ -151,7 +151,7 @@ public class ResourceRequestBuilder {
             Map<String, String> resourceInputData = getResourceInputStr(serviceVnfCust, resourceCustomizationUuid);
 
             // find match in network resource
-            if (resourceInputData.size() == 0) {
+            if (resourceInputData != null && resourceInputData.isEmpty()) {
                 List<Map<String, Object>> serviceNetworkCust =
                         (List<Map<String, Object>>) serviceResources.get("serviceNetworks");
                 resourceInputData = getResourceInputStr(serviceNetworkCust, resourceCustomizationUuid);
@@ -164,15 +164,19 @@ public class ResourceRequestBuilder {
                 }
             }
 
-            String resourceInputStr = resourceInputData.get("resourceInput");
-            ResourceLevel resourceLevel = ResourceLevel.valueOf(resourceInputData.get("nodeType"));
+            String resourceInputStr = null;
+            ResourceLevel resourceLevel = null;
+            if (resourceInputData != null) {
+                resourceInputStr = resourceInputData.get("resourceInput");
+                resourceLevel = ResourceLevel.valueOf(resourceInputData.get("nodeType"));
+            }
 
-            if (resourceInputStr != null && !resourceInputStr.isEmpty()) {
+            if (resourceInputStr != null && !resourceInputStr.isEmpty() && resourceLevel != null) {
                 return getResourceInput(resourceInputStr, serviceInputs, resourceLevel, currentVFData);
             }
 
         } catch (Exception e) {
-            logger.error("not able to retrieve service instance");
+            logger.error("not able to retrieve service instance", e);
         }
         return new HashMap();
     }
-- 
cgit 1.2.3-korg