From: Thanh Ha Date: Sat, 22 Nov 2014 23:30:30 +0000 (-0500) Subject: Fix Sonar Bad practice - Method may fail to close stream X-Git-Tag: release/lithium~780^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=338786f8e06c3ff6d63cd97de24c41ecbf498891 Fix Sonar Bad practice - Method may fail to close stream Change-Id: I8360fce5e14a0b90134004e3255ee979fc73dfa3 Signed-off-by: Thanh Ha --- diff --git a/opendaylight/adsal/web/root/pom.xml b/opendaylight/adsal/web/root/pom.xml index faede10e2d..3d633b6c65 100644 --- a/opendaylight/adsal/web/root/pom.xml +++ b/opendaylight/adsal/web/root/pom.xml @@ -24,6 +24,10 @@ junit junit + + commons-io + commons-io + org.opendaylight.controller clustering.services @@ -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, diff --git a/opendaylight/adsal/web/root/src/main/java/org/opendaylight/controller/web/DaylightWeb.java b/opendaylight/adsal/web/root/src/main/java/org/opendaylight/controller/web/DaylightWeb.java index ca37f4b7c1..090efec31e 100644 --- a/opendaylight/adsal/web/root/src/main/java/org/opendaylight/controller/web/DaylightWeb.java +++ b/opendaylight/adsal/web/root/src/main/java/org/opendaylight/controller/web/DaylightWeb.java @@ -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")