summaryrefslogtreecommitdiffstats
path: root/core/java/com
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-07-18 10:41:41 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-07-18 10:41:41 -0700
commite964387466e380f17e28ab3dd75139509d043ffd (patch)
tree1deb9374ee34a916332df1fe23187e032751a84e /core/java/com
parent03a152d7e72f05456a463f2709ce787119e86f03 (diff)
parent0bad537093ed5b493e4c2af778cf802a2cf2c15f (diff)
downloadframeworks_base-e964387466e380f17e28ab3dd75139509d043ffd.zip
frameworks_base-e964387466e380f17e28ab3dd75139509d043ffd.tar.gz
frameworks_base-e964387466e380f17e28ab3dd75139509d043ffd.tar.bz2
am 0bad5370: Merge "Handle missing and invalid numeric values in XmlUtils."
* commit '0bad537093ed5b493e4c2af778cf802a2cf2c15f': Handle missing and invalid numeric values in XmlUtils.
Diffstat (limited to 'core/java/com')
-rw-r--r--core/java/com/android/internal/util/XmlUtils.java37
1 files changed, 27 insertions, 10 deletions
diff --git a/core/java/com/android/internal/util/XmlUtils.java b/core/java/com/android/internal/util/XmlUtils.java
index fa35308..f40f48c 100644
--- a/core/java/com/android/internal/util/XmlUtils.java
+++ b/core/java/com/android/internal/util/XmlUtils.java
@@ -796,16 +796,8 @@ public class XmlUtils {
}
throw new XmlPullParserException(
"Unexpected end of document in <string>");
- } else if (tagName.equals("int")) {
- res = Integer.parseInt(parser.getAttributeValue(null, "value"));
- } else if (tagName.equals("long")) {
- res = Long.valueOf(parser.getAttributeValue(null, "value"));
- } else if (tagName.equals("float")) {
- res = new Float(parser.getAttributeValue(null, "value"));
- } else if (tagName.equals("double")) {
- res = new Double(parser.getAttributeValue(null, "value"));
- } else if (tagName.equals("boolean")) {
- res = Boolean.valueOf(parser.getAttributeValue(null, "value"));
+ } else if ((res = readThisPrimitiveValueXml(parser, tagName)) != null) {
+ // all work already done by readThisPrimitiveValueXml
} else if (tagName.equals("int-array")) {
parser.next();
res = readThisIntArrayXml(parser, "int-array", name);
@@ -858,6 +850,31 @@ public class XmlUtils {
"Unexpected end of document in <" + tagName + ">");
}
+ private static final Object readThisPrimitiveValueXml(XmlPullParser parser, String tagName)
+ throws XmlPullParserException, java.io.IOException
+ {
+ try {
+ if (tagName.equals("int")) {
+ return Integer.parseInt(parser.getAttributeValue(null, "value"));
+ } else if (tagName.equals("long")) {
+ return Long.valueOf(parser.getAttributeValue(null, "value"));
+ } else if (tagName.equals("float")) {
+ return new Float(parser.getAttributeValue(null, "value"));
+ } else if (tagName.equals("double")) {
+ return new Double(parser.getAttributeValue(null, "value"));
+ } else if (tagName.equals("boolean")) {
+ return Boolean.valueOf(parser.getAttributeValue(null, "value"));
+ } else {
+ return null;
+ }
+ } catch (NullPointerException e) {
+ throw new XmlPullParserException("Need value attribute in <" + tagName + ">");
+ } catch (NumberFormatException e) {
+ throw new XmlPullParserException(
+ "Not a number in value attribute in <" + tagName + ">");
+ }
+ }
+
public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException
{
int type;