Merge "Fix Sonar Bad practice - Method may fail to close stream"
authorTony Tkacik <ttkacik@cisco.com>
Wed, 10 Dec 2014 09:07:01 +0000 (09:07 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 10 Dec 2014 09:07:02 +0000 (09:07 +0000)
opendaylight/adsal/web/root/pom.xml
opendaylight/adsal/web/root/src/main/java/org/opendaylight/controller/web/DaylightWeb.java

index faede10e2d776800dc90bede5ffcc212304c7625..3d633b6c656dbab462cb118586ec2f358906cac0 100644 (file)
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>clustering.services</artifactId>
@@ -90,6 +94,7 @@
               javax.servlet.resources,
               javax.xml.parsers,
               javax.xml.transform,
+              org.apache.commons.io,
               org.apache.commons.logging,
               org.apache.taglibs.standard.functions,
               org.apache.taglibs.standard.resources,
index ca37f4b7c19658ca14facf9af29d6d83d2cd07cb..090efec31e956dc0e8aad6a15a265d3259a90dc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2014 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.web;
 
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -18,6 +19,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import org.apache.commons.io.IOUtils;
 import org.opendaylight.controller.configuration.IConfigurationContainerService;
 import org.opendaylight.controller.configuration.IConfigurationService;
 import org.opendaylight.controller.containermanager.IContainerAuthorization;
@@ -65,11 +67,17 @@ public class DaylightWeb {
     @ResponseBody
     public String getVersion(HttpServletRequest request, @PathVariable("property") String property) {
         Properties prop = new Properties();
+        FileInputStream propertiesFile = null;
         try {
-            prop.load(new FileInputStream("version.properties"));
+            propertiesFile = new FileInputStream("version.properties");
+            prop.load(propertiesFile);
             return prop.getProperty(property+".version");
-        } catch (Exception e) {
+        } catch (IOException e) {
+            // TODO: We should be logging the exception here
+            //       "Failed to open version.properties."
             return null;
+        } finally {
+            IOUtils.closeQuietly(propertiesFile);
         }
     }
     @RequestMapping(value = "web.json")