From c5d14d94cfe09a85e17f258080355e39c5a75a8a Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Mon, 5 Mar 2012 16:51:13 +0000 Subject: [PATCH] Refined fix of #52743 to close output stream before renaming temp file. Windows-only failure in Ant-Build-Matrix. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1297127 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/ReplaceRegExp.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java index 224848630..c950294ef 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java @@ -352,6 +352,8 @@ public class ReplaceRegExp extends Task { throws IOException { File temp = FILE_UTILS.createTempFile("replace", ".txt", null, true, true); try { + boolean changes = false; + InputStream is = new FileInputStream(f); try { Reader r = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is); @@ -362,8 +364,6 @@ public class ReplaceRegExp extends Task { BufferedReader br = new BufferedReader(r); BufferedWriter bw = new BufferedWriter(w); - boolean changes = false; - log("Replacing pattern '" + regex.getPattern(getProject()) + "' with '" + subs.getExpression(getProject()) + "' in '" + f.getPath() + "'" + (byline ? " by line" : "") @@ -455,6 +455,12 @@ public class ReplaceRegExp extends Task { bw.flush(); + } finally { + os.close(); + } + } finally { + is.close(); + } if (changes) { log("File has changed; saving the updated file", Project.MSG_VERBOSE); try { @@ -471,12 +477,6 @@ public class ReplaceRegExp extends Task { } else { log("No change made", Project.MSG_DEBUG); } - } finally { - os.close(); - } - } finally { - is.close(); - } } finally { if (temp != null) { temp.delete();