aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.adt
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-05-30 16:06:03 -0700
committerTor Norbye <tnorbye@google.com>2012-05-30 17:33:18 -0700
commit547c7761208632134d33eace29c81a4e60cd0a69 (patch)
tree84ae7260854779022d621ae2e3001ab351244105 /eclipse/plugins/com.android.ide.eclipse.adt
parent7e4b8e9d595e45baa9d87cdb8282f02759e73abc (diff)
downloadsdk-547c7761208632134d33eace29c81a4e60cd0a69.zip
sdk-547c7761208632134d33eace29c81a4e60cd0a69.tar.gz
sdk-547c7761208632134d33eace29c81a4e60cd0a69.tar.bz2
Fix "Resource leak: <Foo> is never closed"
This changeset fixes various code fragments opening resources without closing them. Change-Id: I6ed48a32dc5de4c11cab394dd3883ebbb54d2938
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/VersionCheck.java12
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java65
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java31
3 files changed, 56 insertions, 52 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/VersionCheck.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/VersionCheck.java
index 594912b..b002ff5 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/VersionCheck.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/VersionCheck.java
@@ -74,12 +74,11 @@ public final class VersionCheck {
int minMajorVersion = -1;
int minMinorVersion = -1;
int minMicroVersion = -1;
- FileReader reader = null;
+ BufferedReader reader = null;
try {
- reader = new FileReader(osLibs + SdkConstants.FN_PLUGIN_PROP);
- BufferedReader bReader = new BufferedReader(reader);
+ reader = new BufferedReader(new FileReader(osLibs + SdkConstants.FN_PLUGIN_PROP));
String line;
- while ((line = bReader.readLine()) != null) {
+ while ((line = reader.readLine()) != null) {
Matcher m = sPluginVersionPattern.matcher(line);
if (m.matches()) {
minMajorVersion = Integer.parseInt(m.group(1));
@@ -139,10 +138,9 @@ public final class VersionCheck {
String osTools = osSdkPath + SdkConstants.OS_SDK_TOOLS_FOLDER;
FullRevision toolsRevision = new FullRevision(Integer.MAX_VALUE);
try {
- reader = new FileReader(osTools + SdkConstants.FN_SOURCE_PROP);
- BufferedReader bReader = new BufferedReader(reader);
+ reader = new BufferedReader(new FileReader(osTools + SdkConstants.FN_SOURCE_PROP));
String line;
- while ((line = bReader.readLine()) != null) {
+ while ((line = reader.readLine()) != null) {
Matcher m = sSourcePropPattern.matcher(line);
if (m.matches()) {
try {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
index 48e01df..5fe47d9 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/actions/DexDumpAction.java
@@ -165,40 +165,43 @@ public class DexDumpAction implements IObjectActionDelegate {
final Process process = Runtime.getRuntime().exec(command);
final BufferedWriter writer = new BufferedWriter(new FileWriter(dstFile));
-
- final String lineSep = AdtUtils.getLineSeparator();
-
- int err = GrabProcessOutput.grabProcessOutput(
- process,
- Wait.WAIT_FOR_READERS,
- new IProcessOutput() {
- @Override
- public void out(@Nullable String line) {
- if (line != null) {
- try {
- writer.write(line);
- writer.write(lineSep);
- } catch (IOException ignore) {}
+ try {
+ final String lineSep = AdtUtils.getLineSeparator();
+
+ int err = GrabProcessOutput.grabProcessOutput(
+ process,
+ Wait.WAIT_FOR_READERS,
+ new IProcessOutput() {
+ @Override
+ public void out(@Nullable String line) {
+ if (line != null) {
+ try {
+ writer.write(line);
+ writer.write(lineSep);
+ } catch (IOException ignore) {}
+ }
}
- }
- @Override
- public void err(@Nullable String line) {
- if (line != null) {
- AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE,
- project, line);
+ @Override
+ public void err(@Nullable String line) {
+ if (line != null) {
+ AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE,
+ project, line);
+ }
}
- }
- });
-
- if (err == 0) {
- // The command worked. In this case we don't remove the
- // temp file in the finally block.
- removeDstFile = false;
- } else {
- AdtPlugin.printErrorToConsole(project,
- "DexDump failed with code " + Integer.toString(err)); //$NON-NLS-1$
- return Status.OK_STATUS;
+ });
+
+ if (err == 0) {
+ // The command worked. In this case we don't remove the
+ // temp file in the finally block.
+ removeDstFile = false;
+ } else {
+ AdtPlugin.printErrorToConsole(project,
+ "DexDump failed with code " + Integer.toString(err)); //$NON-NLS-1$
+ return Status.OK_STATUS;
+ }
+ } finally {
+ writer.close();
}
} catch (InterruptedException e) {
// ?
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java
index 409210d..e2f8a57 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidJarLoader.java
@@ -354,26 +354,29 @@ public class AndroidJarLoader extends ClassLoader implements IAndroidClassLoader
// create streams to read the intermediary archive
FileInputStream fis = new FileInputStream(mOsFrameworkLocation);
ZipInputStream zis = new ZipInputStream(fis);
+ try {
+ // loop on the entries of the intermediary package and put them in the final package.
+ ZipEntry entry;
- // loop on the entries of the intermediary package and put them in the final package.
- ZipEntry entry;
+ while ((entry = zis.getNextEntry()) != null) {
+ // get the name of the entry.
+ String currEntryName = entry.getName();
- while ((entry = zis.getNextEntry()) != null) {
- // get the name of the entry.
- String currEntryName = entry.getName();
+ if (currEntryName.equals(entryName)) {
+ long entrySize = entry.getSize();
+ if (entrySize > Integer.MAX_VALUE) {
+ throw new InvalidAttributeValueException();
+ }
- if (currEntryName.equals(entryName)) {
- long entrySize = entry.getSize();
- if (entrySize > Integer.MAX_VALUE) {
- throw new InvalidAttributeValueException();
+ data = readZipData(zis, (int)entrySize);
+ return data;
}
-
- data = readZipData(zis, (int)entrySize);
- return data;
}
- }
- return null;
+ return null;
+ } finally {
+ zis.close();
+ }
}
/**