From 6f111a4c24ecd42c874d349081efbbd8376ab715 Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Wed, 21 Aug 2019 09:55:13 +0300 Subject: Added null check for latestStack to prevent crash at method calls; moved latestStack declaration according to comment by maintainer Issue-ID: SO-1841 Signed-off-by: Oleksandr Moliavko Change-Id: Ic4bfeca94103f6c902808de39df752569580c066 --- .../org/onap/so/openstack/utils/MsoHeatUtils.java | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'adapters/mso-adapter-utils/src/main/java') diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 6565db7ebc..b5a97f7559 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -327,20 +327,24 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { Integer.parseInt(this.environment.getProperty(pollingMultiplierProp, POLLING_MULTIPLIER_DEFAULT)); int numberOfPollingAttempts = Math.floorDiv((timeoutMinutes * pollingMultiplier), pollingFrequency); Heat heatClient = getHeatClient(cloudSiteId, tenantId); - Stack latestStack = null; while (true) { - latestStack = queryHeatStack(heatClient, stack.getStackName() + "/" + stack.getId()); - statusHandler.updateStackStatus(latestStack); - logger.debug("Polling: {} ({})", latestStack.getStackStatus(), latestStack.getStackName()); - if (stackStatus.equals(latestStack.getStackStatus())) { - if (numberOfPollingAttempts <= 0) { - logger.error("Polling of stack timed out with Status: {}", latestStack.getStackStatus()); + Stack latestStack = queryHeatStack(heatClient, stack.getStackName() + "/" + stack.getId()); + if (latestStack != null) { + statusHandler.updateStackStatus(latestStack); + logger.debug("Polling: {} ({})", latestStack.getStackStatus(), latestStack.getStackName()); + if (stackStatus.equals(latestStack.getStackStatus())) { + if (numberOfPollingAttempts <= 0) { + logger.error("Polling of stack timed out with Status: {}", latestStack.getStackStatus()); + return latestStack; + } + sleep(pollingFrequency * 1000L); + numberOfPollingAttempts -= 1; + } else { return latestStack; } - sleep(pollingFrequency * 1000L); - numberOfPollingAttempts -= 1; } else { - return latestStack; + logger.error("latestStack is null"); + return null; } } } -- cgit 1.2.3-korg