Fix Blocker/Critical sonar issues 65/13065/4
authorshashikanth <shashikanth.vh@huawei.com>
Mon, 18 Sep 2017 09:14:59 +0000 (14:44 +0530)
committerSkip Wonnell <skip@att.com>
Wed, 20 Sep 2017 13:03:54 +0000 (13:03 +0000)
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 <shashikanth.vh@huawei.com>
appc-config/appc-config-adaptor/provider/src/main/java/org/openecomp/appc/ccadaptor/ConfigComponentAdaptor.java

index 02644ac..4e59dd3 100644 (file)
@@ -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
                 {