aboutsummaryrefslogtreecommitdiffstats
path: root/sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-01-03 14:10:03 -0800
committerTor Norbye <tnorbye@google.com>2013-01-03 14:43:37 -0800
commitc7e333b280013fc9fdb540606bedae9be4ae2174 (patch)
tree35b59f98071036373a2974637759512166902854 /sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java
parent5222967cd17a5f9ff2cd82e7292b931c796797ad (diff)
downloadsdk-c7e333b280013fc9fdb540606bedae9be4ae2174.zip
sdk-c7e333b280013fc9fdb540606bedae9be4ae2174.tar.gz
sdk-c7e333b280013fc9fdb540606bedae9be4ae2174.tar.bz2
42271: Open file input streams need to be closed at some point
By default, SAX and DOM parsers close the input source after parsing. However, in SDK common we have a couple of custom parsers using kxml, which does *not* close the input. Rather than fixing all the call sites, this CL makes these parsers behave the same way as the SAX/DOM parsers -- close the input at the end of parse(). Change-Id: I4c5588234865047c88380dc7835beac38817c09f
Diffstat (limited to 'sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java')
-rw-r--r--sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java b/sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java
index c1e45a8..b477b8f 100644
--- a/sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java
+++ b/sdk_common/src/com/android/ide/common/resources/ValidatingResourceParser.java
@@ -17,6 +17,7 @@
package com.android.ide.common.resources;
import com.android.annotations.NonNull;
+import com.google.common.io.Closeables;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
@@ -55,7 +56,7 @@ public class ValidatingResourceParser {
* the context is already tagged as needing a full aapt run.
*
* @param path the full OS path to the file being parsed
- * @param input the input stream of the XML to be parsed
+ * @param input the input stream of the XML to be parsed (will be closed by this method)
* @return true if parsing succeeds and false if it fails
* @throws IOException if reading the contents fails
*/
@@ -63,9 +64,11 @@ public class ValidatingResourceParser {
throws IOException {
// No need to validate framework files
if (mIsFramework) {
+ Closeables.closeQuietly(input);
return true;
}
if (mContext.needsFullAapt()) {
+ Closeables.closeQuietly(input);
return false;
}
@@ -103,6 +106,8 @@ public class ValidatingResourceParser {
path, parser.getLineNumber(), message);
mContext.addError(error);
return false;
+ } finally {
+ Closeables.closeQuietly(input);
}
}