From c6dbc01912b668aa6e9e243cb474d534fd0c10c3 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 5 Aug 2014 09:19:35 -0400 Subject: [PATCH] ensured FileInputStream is correctly closed Former-commit-id: 6e0362476f456e5af07e686fdccf04e600a97de8 --- .../suppression/SuppressionParser.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/suppression/SuppressionParser.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/suppression/SuppressionParser.java index c3cc9c7d6..aa3b0da30 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/suppression/SuppressionParser.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/suppression/SuppressionParser.java @@ -27,11 +27,9 @@ import java.io.Reader; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; - import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; - import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; @@ -68,17 +66,27 @@ public class SuppressionParser { * @throws SuppressionParseException thrown if the xml file cannot be parsed */ public List parseSuppressionRules(File file) throws SuppressionParseException { + FileInputStream fis = null; try { - return parseSuppressionRules(new FileInputStream(file)); + fis = new FileInputStream(file); + return parseSuppressionRules(fis); } catch (IOException ex) { LOGGER.log(Level.FINE, null, ex); throw new SuppressionParseException(ex); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException ex) { + LOGGER.log(Level.FINE, "Unable to close stream", ex); + } + } } } /** * Parses the given xml stream and returns a list of the suppression rules contained. - * + * * @param inputStream an InputStream containing suppression rues * @return a list of suppression rules * @throws SuppressionParseException if the xml cannot be parsed