sonar fix: Rsrc handling in JujuClientManager 13/35213/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:30:54 +0000 (18:00 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:30:54 +0000 (18:00 +0530)
try-with resource issues fixed
file name: JujuClientManager.java

Change-Id: Id547af46419cc0bb75ca29af324ffff2570d83b4
Issue-ID: VFC-805
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/adapter/impl/JujuClientManager.java

index fee0f28..6753108 100644 (file)
@@ -167,16 +167,13 @@ public class JujuClientManager implements IJujuClientManager {
      * @since  NFVO 0.5
      */
     public static String readJujuConfigInfo() {
-        InputStream ins = null;
-
-        BufferedInputStream bins = null;
         String fileContent = null;
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator")
                 + "etc" + System.getProperty("file.separator") + "conf" + System.getProperty("file.separator")
                 + "juju_conf.json";
-        try {
-            ins = new FileInputStream(fileName);
-            bins = new BufferedInputStream(ins);
+        try (
+            InputStream ins = new FileInputStream(fileName);
+            BufferedInputStream bins = new BufferedInputStream(ins)){
 
             byte[] contentByte = new byte[ins.available()];
             int num = bins.read(contentByte);
@@ -186,17 +183,7 @@ public class JujuClientManager implements IJujuClientManager {
             }
         } catch (Exception e) {
             LOG.error(fileName + "is not found!", e);
-        } finally {
-            try {
-                if (ins != null) {
-                    ins.close();
-                }
-                if (bins != null) {
-                    bins.close();
-                }
-            } catch (IOException e) {
-            }
-        }
+        } 
         return fileContent;
     }
     private JSONObject changeDir(String charmPath) {