From 644764ce5452f9534aedf94857055a361f97e6f3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 4 Oct 2011 23:39:57 -0700 Subject: [PATCH] SDK: fix SdkManager class not releasing FileInputStream. Do not merge. In various parts of the code base, I see code that creates a FileInputStrea and never closes it. Unfortunately on Windows that means the file will stay locked for as long as the java process is alive. In this case the SdkManager wasn't closing to input streams which makes the source.properties files locked, and thus it makes it impossible to upgrade/delete the corresponding packages. There are more occurences of this elsewhere in the code. (cherry picked from commit 4c7bf6fe4dbf06f43d86b639ce5144ffeff7a626) Change-Id: I36ad68a216b99fb471b941cb4ccdc88cd3bfad3b --- .../sdklib/src/com/android/sdklib/SdkManager.java | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index 6decab0d1..eab2dbe50 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -559,7 +559,15 @@ public class SdkManager { try { File propFile = new File(secondLevel, SdkConstants.FN_SOURCE_PROP); Properties props = new Properties(); - props.load(new FileInputStream(propFile)); + FileInputStream fis = null; + try { + fis = new FileInputStream(propFile); + props.load(fis); + } finally { + if (fis != null) { + fis.close(); + } + } AndroidVersion propsVersion = new AndroidVersion(props); if (!propsVersion.equals(version)) { @@ -1024,7 +1032,15 @@ public class SdkManager { File sourceProp = new File(folder, SdkConstants.FN_SOURCE_PROP); try { Properties p = new Properties(); - p.load(new FileInputStream(sourceProp)); + FileInputStream fis = null; + try { + fis = new FileInputStream(sourceProp); + p.load(fis); + } finally { + if (fis != null) { + fis.close(); + } + } return new AndroidVersion(p); } catch (FileNotFoundException e) { -- 2.11.0