Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bc99f8e authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Sane undefined behaviors for XmlUtils.

They should treat empty strings as undefined, just like null values.

Bug: 111892141
Test: manual
Change-Id: Ia3eadb1cd1562e73cfa786bfa7fec29994e60a7c
parent 9ba4a5ce
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -63,7 +63,7 @@ public class XmlUtils {
    public static final int
    public static final int
    convertValueToList(CharSequence value, String[] options, int defaultValue)
    convertValueToList(CharSequence value, String[] options, int defaultValue)
    {
    {
        if (null != value) {
        if (!TextUtils.isEmpty(value)) {
            for (int i = 0; i < options.length; i++) {
            for (int i = 0; i < options.length; i++) {
                if (value.equals(options[i]))
                if (value.equals(options[i]))
                    return i;
                    return i;
@@ -79,8 +79,9 @@ public class XmlUtils {
    {
    {
        boolean result = false;
        boolean result = false;


        if (null == value)
        if (TextUtils.isEmpty(value)) {
            return defaultValue;
            return defaultValue;
        }


        if (value.equals("1")
        if (value.equals("1")
        ||  value.equals("true")
        ||  value.equals("true")
@@ -94,8 +95,9 @@ public class XmlUtils {
    public static final int
    public static final int
    convertValueToInt(CharSequence charSeq, int defaultValue)
    convertValueToInt(CharSequence charSeq, int defaultValue)
    {
    {
        if (null == charSeq)
        if (TextUtils.isEmpty(charSeq)) {
            return defaultValue;
            return defaultValue;
        }


        String nm = charSeq.toString();
        String nm = charSeq.toString();


@@ -138,7 +140,7 @@ public class XmlUtils {
    }
    }


    public static int convertValueToUnsignedInt(String value, int defaultValue) {
    public static int convertValueToUnsignedInt(String value, int defaultValue) {
        if (null == value) {
        if (TextUtils.isEmpty(value)) {
            return defaultValue;
            return defaultValue;
        }
        }


@@ -1674,7 +1676,7 @@ public class XmlUtils {
    public static boolean readBooleanAttribute(XmlPullParser in, String name,
    public static boolean readBooleanAttribute(XmlPullParser in, String name,
            boolean defaultValue) {
            boolean defaultValue) {
        final String value = in.getAttributeValue(null, name);
        final String value = in.getAttributeValue(null, name);
        if (value == null) {
        if (TextUtils.isEmpty(value)) {
            return defaultValue;
            return defaultValue;
        } else {
        } else {
            return Boolean.parseBoolean(value);
            return Boolean.parseBoolean(value);
@@ -1711,7 +1713,7 @@ public class XmlUtils {


    public static byte[] readByteArrayAttribute(XmlPullParser in, String name) {
    public static byte[] readByteArrayAttribute(XmlPullParser in, String name) {
        final String value = in.getAttributeValue(null, name);
        final String value = in.getAttributeValue(null, name);
        if (value != null) {
        if (!TextUtils.isEmpty(value)) {
            return Base64.decode(value, Base64.DEFAULT);
            return Base64.decode(value, Base64.DEFAULT);
        } else {
        } else {
            return null;
            return null;