ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r1294780 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
Date Tue, 28 Feb 2012 18:54:16 GMT
Author: jglick
Date: Tue Feb 28 18:54:16 2012
New Revision: 1294780

URL: http://svn.apache.org/viewvc?rev=1294780&view=rev
Log:
#52743: stream leak.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1294780&r1=1294779&r2=1294780&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Feb 28 18:54:16 2012
@@ -12,7 +12,7 @@ Fixed bugs:
    Bugzilla Report 52754.
 
  * Fixed some potential stream leaks.
-   Bugzilla Reports 52738, 52740, 52742.
+   Bugzilla Reports 52738, 52740, 52742, 52743.
 
 Other changes:
 --------------

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=1294780&r1=1294779&r2=1294780&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 Tue
Feb 28 18:54:16 2012
@@ -21,11 +21,11 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.InputStreamReader;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
@@ -351,23 +351,16 @@ public class ReplaceRegExp extends Task 
     protected void doReplace(File f, int options)
          throws IOException {
         File temp = FILE_UTILS.createTempFile("replace", ".txt", null, true, true);
-
-        Reader r = null;
-        Writer w = null;
-        BufferedWriter bw = null;
-
         try {
-            if (encoding == null) {
-                r = new FileReader(f);
-                w = new FileWriter(temp);
-            } else {
-                r = new InputStreamReader(new FileInputStream(f), encoding);
-                w = new OutputStreamWriter(new FileOutputStream(temp),
-                                           encoding);
-            }
+            InputStream is = new FileInputStream(f);
+            try {
+                Reader r = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is);
+                OutputStream os = new FileOutputStream(temp);
+                try {
+                    Writer w = encoding != null ? new OutputStreamWriter(os, encoding) :
new OutputStreamWriter(os);
 
-            BufferedReader br = new BufferedReader(r);
-            bw = new BufferedWriter(w);
+                    BufferedReader br = new BufferedReader(r);
+                    BufferedWriter bw = new BufferedWriter(w);
 
             boolean changes = false;
 
@@ -462,11 +455,6 @@ public class ReplaceRegExp extends Task 
 
             bw.flush();
 
-            r.close();
-            r = null;
-            w.close();
-            w = null;
-
             if (changes) {
                 log("File has changed; saving the updated file", Project.MSG_VERBOSE);
                 try {
@@ -483,10 +471,13 @@ public class ReplaceRegExp extends Task 
             } else {
                 log("No change made", Project.MSG_DEBUG);
             }
+                } finally {
+                    os.close();
+                }
+            } finally {
+                is.close();
+            }
         } finally {
-            FileUtils.close(r);
-            FileUtils.close(bw);
-            FileUtils.close(w);
             if (temp != null) {
                 temp.delete();
             }



Mime
View raw message