sonar fix: Resources & Method handling 21/35221/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:53:59 +0000 (18:23 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 12 Mar 2018 12:53:59 +0000 (18:23 +0530)
try-with resource issues fixed
file name: PyObjectFactory.java, JujuAdapterMgrService.java, VnfRoa.java

Change-Id: I4ac40347e0d053d1fce6299e68dde6629b08badd
Issue-ID: VFC-806
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/api/internalsvc/impl/JujuAdapterMgrService.java
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/juju/PyObjectFactory.java
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoa.java

index c803d3e..b7e6094 100644 (file)
@@ -80,17 +80,15 @@ public class JujuAdapterMgrService implements IJujuAdapterMgrService {
      * @since NFVO 0.5
      */
     public static String readJujuAdapterInfoFromJson() throws IOException {
-        InputStream ins = null;
-        BufferedInputStream bins = null;
         String fileContent = "";
 
         String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot()
                 + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR)
                 + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + Constant.JUJUADAPTERINFO;
 
-        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);
@@ -100,15 +98,7 @@ public class JujuAdapterMgrService implements IJujuAdapterMgrService {
             }
         } catch(FileNotFoundException e) {
             LOG.error(fileName + "is not found!", e, JujuAdapterMgrService.class);
-        } finally {
-            if(null != ins) {
-                ins.close();
-            }
-
-            if(null != bins) {
-                bins.close();
-            }
-        }
+        } 
 
         return fileContent;
     }
index 35b4793..a664ed6 100644 (file)
@@ -42,7 +42,7 @@ public class PyObjectFactory {
      * @since NFVO 0.5
      */
     public static PyObjectFactory build(String envName) {
-        PythonInterpreter interpreter = new PythonInterpreter();
+        try(PythonInterpreter interpreter = new PythonInterpreter()){
         
         interpreter.exec("from jujuclient import Environment");
         
@@ -50,6 +50,7 @@ public class PyObjectFactory {
         PyObject env = environmentClass.__call__();
         environmentObj = env.invoke("connect", new PyString(envName));
         return new PyObjectFactory();
+       }
     }
 
     /**
index d7aa919..1f2a97c 100644 (file)
@@ -89,7 +89,7 @@ public class VnfRoa {
 
     @POST
     @Path("/vnfminfo")
-    public String setVNFMInfo(@Context HttpServletRequest context, @Context HttpServletResponse resp)
+    public static String setVNFMInfo(@Context HttpServletRequest context, @Context HttpServletResponse resp)
             throws ServiceException {
         JSONObject result = new JSONObject();
         result.put("retCode", Constant.REST_SUCCESS);