Fix sonar blocker issues in ccsdk/core module
authorArun S. Yerra <arun.yerra@huawei.com>
Thu, 7 Sep 2017 23:21:23 +0000 (16:21 -0700)
committerArun S. Yerra <arun.yerra@huawei.com>
Thu, 7 Sep 2017 23:25:35 +0000 (16:25 -0700)
Sonarqube report for CCSDK core identfied some blcoker issues. This fix addresses those bugs.

Issue-Id: CCSDK-84

Change-Id: Ie6ff19b7b0815a129f9809243e8e3eb0a64144ab
Signed-off-by: Arun S. Yerra <arun.yerra@huawei.com>
sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/FileRecorder.java

index f11b362..9216519 100644 (file)
@@ -132,7 +132,7 @@ public class SvcLogicDblibStore implements SvcLogicStore {
                        String mode) throws SvcLogicException {
 
                DbLibService dbSvc = getDbLibService();
-
+               PreparedStatement fetchGraphStmt = null;
                Connection dbConn = null;
                SvcLogicGraph retval = null;
                ResultSet results = null;
@@ -146,7 +146,7 @@ public class SvcLogicDblibStore implements SvcLogicStore {
 
                try {
                        dbConn = ((DBResourceManager) dbSvc).getConnection();
-                       PreparedStatement fetchGraphStmt;
+
 
                        ArrayList<String> args = new ArrayList<String>();
                        args.add(module);
@@ -193,6 +193,13 @@ public class SvcLogicDblibStore implements SvcLogicStore {
                } catch (Exception e) {
                        throw new ConfigurationException("Graph processing failed", e);
                } finally {
+                       try {
+                               if (fetchGraphStmt != null) {
+                                       fetchGraphStmt.close();
+                               }
+                       } catch (SQLException e) {
+                               LOG.info(e.getMessage());
+                       }
                        if (results != null) {
                                try {
                                        results.close();
@@ -267,12 +274,12 @@ public class SvcLogicDblibStore implements SvcLogicStore {
                }
 
                Connection dbConn = null;
-
+               PreparedStatement storeGraphStmt = null;
                try {
                        dbConn = ((DBResourceManager) dbSvc).getConnection();
                        boolean oldAutoCommit = dbConn.getAutoCommit();
                        dbConn.setAutoCommit(false);
-                       PreparedStatement storeGraphStmt = dbConn
+                       storeGraphStmt = dbConn
                                        .prepareStatement(storeGraphSql);
                        storeGraphStmt.setString(1, graph.getModule());
                        storeGraphStmt.setString(2, graph.getRpc());
@@ -288,6 +295,13 @@ public class SvcLogicDblibStore implements SvcLogicStore {
                } catch (Exception e) {
                        throw new SvcLogicException("Could not write object to database", e);
                } finally {
+                       try {
+                               if (storeGraphStmt != null) {
+                                       storeGraphStmt.close();
+                               }
+                       } catch (SQLException e) {
+                               LOG.info(e.getMessage());
+                       }
                        try {
                                if (dbConn != null && !dbConn.isClosed()) {
                                        dbConn.close();
index 1143ef7..4a60de9 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.ccsdk.sli.core.sli.recording;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
+import java.io.IOException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -82,6 +83,7 @@ public class FileRecorder implements SvcLogicRecorder {
                
                File recordFile = new File(fileName);
                PrintWriter recPrinter = null;
+               FileWriter fileWriter = null;
                Date now = new Date();
 
                TimeZone tz = TimeZone.getTimeZone("UTC");
@@ -95,7 +97,7 @@ public class FileRecorder implements SvcLogicRecorder {
                try
                {
                
-                       recPrinter = new PrintWriter(new FileWriter(recordFile, true));
+                       recPrinter = new PrintWriter(fileWriter = new FileWriter(recordFile, true));
                        recPrinter.println(record);
                }
                catch (Exception e)
@@ -108,6 +110,14 @@ public class FileRecorder implements SvcLogicRecorder {
                        {
                                recPrinter.close();
                        }
+                       if (fileWriter != null)
+                       {
+                               try {
+                                       fileWriter.close();
+                               } catch (IOException e) {
+
+                               }
+                       }
                }