From 763b15fd4fd4cf92b6aef2e29de98008894413a5 Mon Sep 17 00:00:00 2001 From: Kaloian Doganov Date: Fri, 2 Mar 2012 22:02:43 +0200 Subject: Close the dependency file after reading it. The dependency file will be eventually closed by the finalize() method at some point, but it is not known when. In the meantime, the Ant recipe continues execution and may try to move or delete this file. At that point the build may fail because the file is still open. The solution is to explicitly close the BufferedReader opened by DependencyGraph.readFile(), so the underlying file is closed as soon as reading is finished. Change-Id: If25f0d430191f4265a73a0e6adc3d81764c63758 Signed-off-by: Kaloian Doganov --- anttasks/src/com/android/ant/DependencyGraph.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'anttasks/src') diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java index 8671359..ef059b9 100644 --- a/anttasks/src/com/android/ant/DependencyGraph.java +++ b/anttasks/src/com/android/ant/DependencyGraph.java @@ -436,13 +436,17 @@ public class DependencyGraph { if (fStream != null) { BufferedReader reader = new BufferedReader(new InputStreamReader(fStream)); - String line; - StringBuilder total = new StringBuilder(reader.readLine()); - while ((line = reader.readLine()) != null) { - total.append('\n'); - total.append(line); + try { + String line; + StringBuilder total = new StringBuilder(reader.readLine()); + while ((line = reader.readLine()) != null) { + total.append('\n'); + total.append(line); + } + return total.toString(); + } finally { + reader.close(); } - return total.toString(); } } catch (IOException e) { // we'll just return null -- cgit v1.1