ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r905179 - in /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs: Execute.java email/Message.java optional/Cab.java optional/ReplaceRegExp.java optional/junit/BriefJUnitResultFormatter.java optional/junit/FailureRecorder.java
Date Mon, 01 Feb 2010 05:35:08 GMT
Author: bodewig
Date: Mon Feb  1 05:35:08 2010
New Revision: 905179

URL: http://svn.apache.org/viewvc?rev=905179&view=rev
Log:
a few more places where FileUtils.close can be used + a few places where a BufferedWriter
might be unflushed when the underlying stream gets closed.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Execute.java Mon Feb  1 05:35:08
2010
@@ -1203,9 +1203,7 @@
                     out.write(cmd[i]);
                 }
             } finally {
-                if (out != null) {
-                    out.close();
-                }
+                FileUtils.close(out);
             }
             return script;
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java Mon Feb  1 05:35:08
2010
@@ -26,6 +26,7 @@
 import java.io.PrintStream;
 
 import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Class representing an email message.
@@ -115,7 +116,9 @@
          throws IOException {
         // We need character encoding aware printing here.
         // So, using BufferedWriter over OutputStreamWriter instead of PrintStream
-        BufferedWriter out
+        BufferedWriter out = null;
+        try {
+            out
             = charset != null ? new BufferedWriter(new OutputStreamWriter(ps, charset))
                               : new BufferedWriter(new OutputStreamWriter(ps));
         if (messageSource != null) {
@@ -137,6 +140,9 @@
             out.newLine();
         }
         out.flush();
+        } finally {
+            FileUtils.close(out);
+        }
     }
 
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java Mon Feb  1 05:35:08
2010
@@ -179,14 +179,18 @@
         throws IOException {
         File listFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
 
-        BufferedWriter writer = new BufferedWriter(new FileWriter(listFile));
+        BufferedWriter writer = null;
+        try {
+            writer = new BufferedWriter(new FileWriter(listFile));
 
         int size = files.size();
         for (int i = 0; i < size; i++) {
             writer.write('\"' + files.elementAt(i).toString() + '\"');
             writer.newLine();
         }
-        writer.close();
+        } finally {
+            FileUtils.close(writer);
+        }
 
         return listFile;
     }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java Mon
Feb  1 05:35:08 2010
@@ -354,6 +354,7 @@
 
         Reader r = null;
         Writer w = null;
+        BufferedWriter bw = null;
 
         try {
             if (encoding == null) {
@@ -366,7 +367,7 @@
             }
 
             BufferedReader br = new BufferedReader(r);
-            BufferedWriter bw = new BufferedWriter(w);
+            bw = new BufferedWriter(w);
 
             boolean changes = false;
 
@@ -484,6 +485,7 @@
             }
         } finally {
             FileUtils.close(r);
+            FileUtils.close(bw);
             FileUtils.close(w);
             if (temp != null) {
                 temp.delete();

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java
Mon Feb  1 05:35:08 2010
@@ -169,10 +169,14 @@
                 output.write(sb.toString());
                 resultWriter.close();
                 output.write(results.toString());
-                output.flush();
             } catch (IOException ex) {
                 throw new BuildException(ex);
             } finally {
+                try {
+                    output.flush();
+                } catch (IOException ex) {
+                    // swallow, there has likely been an exception before this
+                }
                 if (out != System.out && out != System.err) {
                     FileUtils.close(out);
                 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java?rev=905179&r1=905178&r2=905179&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/junit/FailureRecorder.java
Mon Feb  1 05:35:08 2010
@@ -255,9 +255,10 @@
             createSuiteMethod();
             createClassFooter();
 
-            FileUtils.close(writer);
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
+            FileUtils.close(writer);
         }
     }
 



Mime
View raw message