Fix closure by try resource approach 65/31365/2
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 12 Feb 2018 04:52:53 +0000 (10:22 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 12 Feb 2018 05:56:29 +0000 (11:26 +0530)
Issue-ID: CLI-92

Change-Id: I6375058625b51d2d15d397163c0aa20025114bc2
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java

index 81589b0..e9ea81d 100644 (file)
@@ -42,12 +42,12 @@ public class OnapCommandHelperUtils {
      */
     public static String findLastBuildTime() {
         String impBuildDate = "";
+        JarFile jar = null;
         try
         {
             String path = OnapCommandUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
-            JarFile jar = new JarFile(path);
+            jar = new JarFile(path);
             Manifest manifest = jar.getManifest();
-            jar.close();
 
             Attributes attributes = manifest.getMainAttributes();
 
@@ -56,6 +56,14 @@ public class OnapCommandHelperUtils {
         catch (IOException e)  // NOSONAR
         {
             //Ignore it as it will never occur
+        } finally {
+            if (jar != null) {
+                try {
+                    jar.close();
+                } catch (IOException e) { // NOSONAR
+                    //Ignore it as it will never occur
+                }
+            }
         }
 
         return impBuildDate;