From b59ab6b65a4f81464a970e579107d0828f78aadc Mon Sep 17 00:00:00 2001 From: shashikanth Date: Mon, 18 Sep 2017 14:44:59 +0530 Subject: Fix Blocker/Critical sonar issues Fix Blocker/Critical sonar issues in appc module https://sonar.onap.org/issues/search#issues=AV36Pm5i89V-MRZU59OH Fixed NullPointerException might be thrown as 'data' is nullable here Issue-Id: APPC-186 Change-Id: I65ee1745f5fd5a7f7ac3365704943b25a9341e8a Signed-off-by: shashikanth.vh --- .../appc/ccadaptor/ConfigComponentAdaptor.java | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/openecomp/appc/ccadaptor/ConfigComponentAdaptor.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/openecomp/appc/ccadaptor/ConfigComponentAdaptor.java index 02644ac92..4e59dd345 100644 --- a/appc-config/appc-config-adaptor/provider/src/main/java/org/openecomp/appc/ccadaptor/ConfigComponentAdaptor.java +++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/openecomp/appc/ccadaptor/ConfigComponentAdaptor.java @@ -165,8 +165,6 @@ public class ConfigComponentAdaptor implements SvcLogicAdaptor password = EncryptionTool.getInstance().decrypt(password); String fullPathFileName = parameters.get("fullPathFileName"); String data = null; - if (key.equals("put")) - data = parameters.get("data"); SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper(); log.debug("SCP: SshJcraftWrapper has been instantiated"); @@ -175,21 +173,27 @@ public class ConfigComponentAdaptor implements SvcLogicAdaptor { if (key.equals("put")) { - debugLog.printRTAriDebug(fnName, "Command is for put: Length of data is: " + data.length()); - InputStream is = new ByteArrayInputStream(data.getBytes()); - log.debug("SCP: Doing a put: fullPathFileName=" + fullPathFileName); - debugLog.printRTAriDebug(fnName, "SCP: Doing a put: fullPathFileName=" + fullPathFileName); - sshJcraftWrapper.put(is, fullPathFileName, host, loginId, password); - try - { - debugLog.printRTAriDebug(fnName, "Sleeping for 180 seconds...."); - Thread.sleep(1000 * 180); - debugLog.printRTAriDebug(fnName, "Woke up...."); - } - catch (java.lang.InterruptedException ee) - { - boolean ignore = true; - } + data = parameters.get("data"); + if (data != null) { + debugLog.printRTAriDebug(fnName, "Command is for put: Length of data is: " + data.length()); + InputStream is = new ByteArrayInputStream(data.getBytes()); + log.debug("SCP: Doing a put: fullPathFileName=" + fullPathFileName); + debugLog.printRTAriDebug(fnName, "SCP: Doing a put: fullPathFileName=" + fullPathFileName); + sshJcraftWrapper.put(is, fullPathFileName, host, loginId, password); + try + { + debugLog.printRTAriDebug(fnName, "Sleeping for 180 seconds...."); + Thread.sleep(1000 * 180); + debugLog.printRTAriDebug(fnName, "Woke up...."); + } + catch (java.lang.InterruptedException ee) + { + boolean ignore = true; + } + } else { + r.code = HttpURLConnection.HTTP_INTERNAL_ERROR; + log.debug(fnName + " Command is for put: data is null"); + } } else // Must be a get { -- cgit 1.2.3-korg