Handle null condition in ResourceImportManager 81/106381/2
authorRodrigo Lima <rodrigo.lima@yoppworks.com>
Tue, 21 Apr 2020 19:17:29 +0000 (15:17 -0400)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Wed, 22 Apr 2020 11:00:14 +0000 (11:00 +0000)
- check if parentResource null in methods setRequirements and setCapabilities

Issue-ID: SDC-2912
Signed-off-by: Rodrigo Lima <rodrigo.lima@yoppworks.com>
Change-Id: I1ea5a8cf26e3883b5d26fb970bc0abc4cbf1ee9a

catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java

index 6b0b6bf..79543ce 100644 (file)
@@ -461,11 +461,11 @@ public class ResourceImportManager {
                 Boolean validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef
                         .getCapability(), requirementDef.getName());
                 if (!validateVsParentCap) {
-                    log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResource
-                            .getName());
+                    String parentResourceName = parentResource != null ? parentResource.getName() : "";
+                    log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResourceName);
                     throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef
                             .getName()
-                            .toLowerCase(), parentResource.getName());
+                            .toLowerCase(), parentResourceName);
                 }
             }
             if (moduleRequirements.size() > 0) {
@@ -623,11 +623,12 @@ public class ResourceImportManager {
                 if (!validateVsParentCap) {
                     // Here parentResource is for sure not null, so it's
                     // null-safe
-                    log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResource
-                            .getName());
+                    // Check added to avoid sonar warning
+                    String parentResourceName = parentResource != null ? parentResource.getName() : "";
+                    log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResourceName);
                     throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef
                             .getName()
-                            .toLowerCase(), parentResource.getName());
+                            .toLowerCase(), parentResourceName);
                 }
             }
             if (moduleCapabilities.size() > 0) {