aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-22 12:22:03 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-06-22 12:22:03 +0200
commitd28d9689859d63d6543ff2b55026fc2db8cb79f6 (patch)
treee5711e990f1d52af6e23c6147ecb751484096e5d
parent34454ef2ecf22910a6d4da2e3c895b2cd8c0f76d (diff)
make sure that we always release wake lock even after throwing exception
-rw-r--r--src/main/java/eu/siacs/conversations/xml/XmlReader.java33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/main/java/eu/siacs/conversations/xml/XmlReader.java b/src/main/java/eu/siacs/conversations/xml/XmlReader.java
index b8aa3aa0..48569086 100644
--- a/src/main/java/eu/siacs/conversations/xml/XmlReader.java
+++ b/src/main/java/eu/siacs/conversations/xml/XmlReader.java
@@ -22,8 +22,7 @@ public class XmlReader {
public XmlReader(WakeLock wakeLock) {
this.parser = Xml.newPullParser();
try {
- this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,
- true);
+ this.parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
} catch (XmlPullParserException e) {
Log.d(Config.LOGTAG, "error setting namespace feature on parser");
}
@@ -42,13 +41,6 @@ public class XmlReader {
}
}
- public InputStream getInputStream() throws IOException {
- if (this.is == null) {
- throw new IOException();
- }
- return is;
- }
-
public void reset() throws IOException {
if (this.is == null) {
throw new IOException();
@@ -65,11 +57,11 @@ public class XmlReader {
try {
wakeLock.release();
} catch (RuntimeException re) {
+ Log.d(Config.LOGTAG,"runtime exception releasing wakelock before reading tag "+re.getMessage());
}
}
try {
- while (this.is != null
- && parser.next() != XmlPullParser.END_DOCUMENT) {
+ while (this.is != null && parser.next() != XmlPullParser.END_DOCUMENT) {
wakeLock.acquire();
if (parser.getEventType() == XmlPullParser.START_TAG) {
Tag tag = Tag.start(parser.getName());
@@ -83,21 +75,22 @@ public class XmlReader {
}
return tag;
} else if (parser.getEventType() == XmlPullParser.END_TAG) {
- Tag tag = Tag.end(parser.getName());
- return tag;
+ return Tag.end(parser.getName());
} else if (parser.getEventType() == XmlPullParser.TEXT) {
- Tag tag = Tag.no(parser.getText());
- return tag;
+ return Tag.no(parser.getText());
}
}
+
+ } catch (Exception e) {
+ throw new IOException("xml parser mishandled "+e.getClass().getName(), e);
+ } finally {
if (wakeLock.isHeld()) {
try {
wakeLock.release();
} catch (RuntimeException re) {
+ Log.d(Config.LOGTAG,"runtime exception releasing wakelock after exception "+re.getMessage());
}
}
- } catch (Exception e) {
- throw new IOException("xml parser mishandled "+e.getClass().getName(), e);
}
return null;
}
@@ -108,13 +101,13 @@ public class XmlReader {
element.setAttributes(currentTag.getAttributes());
Tag nextTag = this.readTag();
if (nextTag == null) {
- throw new IOException("unterupted mid tag");
+ throw new IOException("interrupted mid tag");
}
if (nextTag.isNo()) {
element.setContent(nextTag.getName());
nextTag = this.readTag();
if (nextTag == null) {
- throw new IOException("unterupted mid tag");
+ throw new IOException("interrupted mid tag");
}
}
while (!nextTag.isEnd(element.getName())) {
@@ -124,7 +117,7 @@ public class XmlReader {
}
nextTag = this.readTag();
if (nextTag == null) {
- throw new IOException("unterupted mid tag");
+ throw new IOException("interrupted mid tag");
}
}
return element;