Fix few Blocker sonar issues
authorGaurav Agrawal <gaurav.agrawal@huawei.com>
Fri, 8 Sep 2017 14:28:55 +0000 (19:58 +0530)
committerGaurav Agrawal <gaurav.agrawal@huawei.com>
Fri, 8 Sep 2017 15:38:12 +0000 (21:08 +0530)
Fix few Blocker sonar issues in CCSDK SLI Northbound
https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.northbound%3Accsdk-sli-northbound#resolved=false|severities=BLOCKER

Change-Id: I7229c7e2a0dabc0ff789b91ae413b9a15ef3cbad
Issue-Id: CCSDK-67
Signed-off-by: Gaurav Agrawal <gaurav.agrawal@huawei.com>
ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebCallback.java

index 73e8fe5..e7a42bc 100644 (file)
@@ -208,12 +208,8 @@ public class SdncUebCallback implements INotificationCallback {
                Properties props = new Properties();
                props.load(new FileInputStream(propFile));
 
-               try {
-                       jdbcDataSource = new DBResourceManager(props);
-               } catch(Throwable exc) {
-                       LOG.error("", exc);
-               }
-
+               jdbcDataSource = new DBResourceManager(props);
+               
                if(((DBResourceManager)jdbcDataSource).isActive()){
                        LOG.warn( "DBLIB: JDBC DataSource has been initialized.");
                } else {
@@ -405,8 +401,7 @@ public class SdncUebCallback implements INotificationCallback {
 
         boolean writeSucceeded = false;
 
-        try {
-            FileWriter spoolFileWriter = new FileWriter(spoolFile);
+        try (FileWriter spoolFileWriter = new FileWriter(spoolFile)) {
             spoolFileWriter.write(payload);
             spoolFileWriter.close();
             writeSucceeded = true;
@@ -916,11 +911,8 @@ public class SdncUebCallback implements INotificationCallback {
         msgBuffer.append("<artifact-version>"+artifact.getArtifactVersion()+"</artifact-version>\n");
 
 
-        try {
-            BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()));
-
+        try (BufferedReader rdr = new BufferedReader(new FileReader(artifact.getFile()))){
             String curLine = rdr.readLine();
-
             while (curLine != null) {
 
                 if (!curLine.startsWith("<?")) {
@@ -928,8 +920,6 @@ public class SdncUebCallback implements INotificationCallback {
                 }
                 curLine = rdr.readLine();
             }
-            rdr.close();
-
         } catch (Exception e) {
             LOG.error("Could not process spool file "+artifact.getFile().getName(), e);
                        return(DistributionStatusEnum.DEPLOY_ERROR);