From 34d989b755a47e900824a0316b122226ee05f7e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Thu, 26 Sep 2019 09:21:39 +0300 Subject: Added null checks for bp to prevent exceptions at bp.getId() calls; fixed omissions in methods control logic; removed unneeded catch blocks Issue-ID: SO-1841 Signed-off-by: Oleksandr Moliavko Change-Id: I8347b953381ebb4a112a22fc8c58a9a32f2dbfb7 --- .../onap/so/cloudify/utils/MsoCloudifyUtils.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'adapters/mso-adapter-utils/src/main/java/org/onap') diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java index 2a17656f1d..f1c42bb4a5 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java @@ -751,16 +751,19 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint exists: {}", bp.getId()); - return true; + if (bp != null) { + logger.debug("Blueprint exists: {}", bp.getId()); + return true; + } else { + logger.debug("Null blueprint!"); + return false; + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { return false; } else { throw ce; } - } catch (Exception e) { - throw e; } } @@ -799,8 +802,12 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); try { Blueprint bp = getRequest.execute(); - logger.debug("Blueprint {} already exists.", bp.getId()); - return false; + if (bp != null) { + logger.debug("Blueprint {} already exists.", bp.getId()); + return false; + } else { + logger.debug("Null blueprint!"); + } } catch (CloudifyResponseException ce) { if (ce.getStatus() == 404) { // This is the expected result. @@ -808,8 +815,6 @@ public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { } else { throw ce; } - } catch (Exception e) { - throw e; } // Create a blueprint ZIP file in memory -- cgit 1.2.3-korg