ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 7302] New: - Files left open in FileUtils
Date Wed, 20 Mar 2002 23:37:10 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7302>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7302

Files left open in FileUtils

           Summary: Files left open in FileUtils
           Product: Ant
           Version: 1.5 alpha (nightly)
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Core tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: Jed_Anderson@oti.com


In org.apache.tools.ant.util.FileUtils there is the method:
    public void copyFile(File sourceFile, File destFile,
                         FilterSetCollection filters, Vector filterChains,
                         boolean overwrite, boolean preserveLastModified,
                         String encoding, Project project)

On line 379 & 380 and 392 & 393the in and out streams are closed.  The code
should be wrapped in try {} finally {} blocks so that the files get closed even
if the code above them fails.

Normally, this code can fail and noboby will see it because java cleans up open
files on exit, however, if you keep ant in memory in a program that has an
extended lifecycle, these open files can become problematic.

If I may, I'd like to suggest the following code, it will drop an IOException if
both close() calls throw IOExceptions, however, I don't think you can write this
code safely without redesigning the entire class so that none of the copy
methods throw IOException.

try {
   // open streams and do work (right now this code starts on line 341)
} finally {
   try {
      if (out != null)
         out.close();
   } finally {
      if (in != null)
         in.close();
   }
}

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message