From 796b6c0491833587ba096a33bd0d34329f6213c5 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 13 Oct 2011 18:47:02 -0700 Subject: Code cleanup: make sure FileInputStreams are closed. Various places of the code construct a new FileInputStream on the fly and give it to another method. One many occasions the stream is never properly closed, which can lock files on Windows. 2 specific cases: - Properties.load() doesn't seem to close its input (when looking at the source bundled with the JRE). - The doc of InputSource (used by various XML parsers like the pull parser) indicates the caller should in general not close the stream and the parser itself should do it. Change-Id: I622b54a22f97ed2c9c8fdc56ccde331207d9d212 --- anttasks/src/com/android/ant/TaskHelper.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'anttasks') diff --git a/anttasks/src/com/android/ant/TaskHelper.java b/anttasks/src/com/android/ant/TaskHelper.java index a360eaf..8a3d6bc 100644 --- a/anttasks/src/com/android/ant/TaskHelper.java +++ b/anttasks/src/com/android/ant/TaskHelper.java @@ -59,7 +59,20 @@ final class TaskHelper { // tools folder must exist, or this custom task wouldn't run! File toolsFolder= new File(sdkFile, SdkConstants.FD_TOOLS); File sourceProp = new File(toolsFolder, SdkConstants.FN_SOURCE_PROP); - p.load(new FileInputStream(sourceProp)); + + FileInputStream fis = null; + try { + fis = new FileInputStream(sourceProp); + p.load(fis); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException ignore) { + } + } + } + String value = p.getProperty("Pkg.Revision"); //$NON-NLS-1$ if (value != null) { return Integer.parseInt(value); -- cgit v1.1