Browse Source

even more FileUtils.close and try-with-resources cases

master
Stefan Bodewig 9 years ago
parent
commit
0906b0ad94
6 changed files with 12 additions and 44 deletions
  1. +1
    -6
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +3
    -7
      src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
  3. +2
    -10
      src/main/org/apache/tools/ant/taskdefs/SQLExec.java
  4. +2
    -7
      src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
  5. +3
    -7
      src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java
  6. +1
    -7
      src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java

+ 1
- 6
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -1407,12 +1407,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*/ */
public synchronized void cleanup() { public synchronized void cleanup() {
for (final Enumeration<JarFile> e = jarFiles.elements(); e.hasMoreElements();) { for (final Enumeration<JarFile> e = jarFiles.elements(); e.hasMoreElements();) {
final JarFile jarFile = e.nextElement();
try {
jarFile.close();
} catch (final IOException ioe) {
// ignore
}
FileUtils.close(e.nextElement());
} }
jarFiles = new Hashtable<File, JarFile>(); jarFiles = new Hashtable<File, JarFile>();
if (project != null) { if (project != null) {


+ 3
- 7
src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java View File

@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Logs standard output and error of a subprocess to the log system of ant. * Logs standard output and error of a subprocess to the log system of ant.
@@ -59,12 +60,7 @@ public class LogStreamHandler extends PumpStreamHandler {
*/ */
public void stop() { public void stop() {
super.stop(); super.stop();
try {
getErr().close();
getOut().close();
} catch (IOException e) {
// plain impossible
throw new BuildException(e);
}
FileUtils.close(getErr());
FileUtils.close(getOut());
} }
} }

+ 2
- 10
src/main/org/apache/tools/ant/taskdefs/SQLExec.java View File

@@ -692,19 +692,11 @@ public class SQLExec extends JDBCTask {
} }
} finally { } finally {
try { try {
if (getStatement() != null) {
getStatement().close();
}
} catch (SQLException ex) {
// ignore
}
try {
if (getConnection() != null) {
getConnection().close();
}
FileUtils.close(getStatement());
} catch (SQLException ex) { } catch (SQLException ex) {
// ignore // ignore
} }
FileUtils.close(getConnection());
} }


log(goodSql + " of " + totalSql + " SQL statements executed successfully"); log(goodSql + " of " + totalSql + " SQL statements executed successfully");


+ 2
- 7
src/main/org/apache/tools/ant/taskdefs/condition/Socket.java View File

@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Condition to wait for a TCP/IP socket to have a listener. Its attributes are: * Condition to wait for a TCP/IP socket to have a listener. Its attributes are:
@@ -73,13 +74,7 @@ public class Socket extends ProjectComponent implements Condition {
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} finally { } finally {
if (s != null) {
try {
s.close();
} catch (IOException ioe) {
// Intentionally left blank
}
}
FileUtils.close(s);
} }
return true; return true;
} }


+ 3
- 7
src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java View File

@@ -22,6 +22,7 @@ import java.io.IOException;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.PumpStreamHandler; import org.apache.tools.ant.taskdefs.PumpStreamHandler;
import org.apache.tools.ant.util.FileUtils;


/** /**
* A dummy stream handler that just passes stuff to the parser. * A dummy stream handler that just passes stuff to the parser.
@@ -49,13 +50,8 @@ class RedirectingStreamHandler


public void stop() { public void stop() {
super.stop(); super.stop();
try {
getErr().close();
getOut().close();
} catch (final IOException e) {
// plain impossible
throw new BuildException(e);
}
FileUtils.close(getErr());
FileUtils.close(getOut());
} }
} }



+ 1
- 7
src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java View File

@@ -267,16 +267,10 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer {
} }
} else { } else {
// must be a zip of some sort // must be a zip of some sort
ZipFile zipFile = null;
try {
zipFile = new ZipFile(element);
try (ZipFile zipFile = new ZipFile(element)) {
if (zipFile.getEntry(resourceLocation) != null) { if (zipFile.getEntry(resourceLocation) != null) {
return element; return element;
} }
} finally {
if (zipFile != null) {
zipFile.close();
}
} }
} }
} }


Loading…
Cancel
Save