From 8a5065a44e64cd9eabbb2c16d262eb88be3d0c43 Mon Sep 17 00:00:00 2001 From: Rodrigo Lima Date: Tue, 21 Apr 2020 15:17:29 -0400 Subject: Handle null condition in ResourceImportManager - check if parentResource null in methods setRequirements and setCapabilities Issue-ID: SDC-2912 Signed-off-by: Rodrigo Lima Change-Id: I1ea5a8cf26e3883b5d26fb970bc0abc4cbf1ee9a --- .../sdc/be/components/impl/ResourceImportManager.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 6b0b6bf81c..79543ce5cf 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -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) { -- cgit 1.2.3-korg