You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/02/17 23:26:07 UTC

svn commit: r1783480 - /jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java

Author: pmouawad
Date: Fri Feb 17 23:26:07 2017
New Revision: 1783480

URL: http://svn.apache.org/viewvc?rev=1783480&view=rev
Log:
Fix leak reported by sonar

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java?rev=1783480&r1=1783479&r2=1783480&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java Fri Feb 17 23:26:07 2017
@@ -22,7 +22,6 @@ import java.io.BufferedInputStream;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -30,9 +29,8 @@ import javax.xml.parsers.ParserConfigura
 import javax.xml.transform.TransformerException;
 
 import org.apache.jmeter.util.XPathUtil;
-import org.slf4j.LoggerFactory;
-import org.apache.jorphan.util.JOrphanUtils;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
@@ -68,13 +66,11 @@ public class XPathFileContainer {
 
     private NodeList load(String xpath) throws IOException, FileNotFoundException, ParserConfigurationException, SAXException,
             TransformerException {
-        InputStream fis = null;
         NodeList nl = null;
-        try {
+        try ( FileInputStream fis = new FileInputStream(fileName);
+                BufferedInputStream bis = new BufferedInputStream(fis) ){
             DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-
-            fis = new BufferedInputStream(new FileInputStream(fileName));
-            nl = XPathUtil.selectNodeList(builder.parse(fis), xpath);
+            nl = XPathUtil.selectNodeList(builder.parse(bis), xpath);
             if(log.isDebugEnabled()) {
                 log.debug("found " + nl.getLength());
             }
@@ -82,9 +78,7 @@ public class XPathFileContainer {
                 | ParserConfigurationException | IOException e) {
             log.warn(e.toString());
             throw e;
-        } finally {
-            JOrphanUtils.closeQuietly(fis);
-        }
+        } 
         return nl;
     }