MuntashirAkon/AppManager · error · XmlPullParserException

Invalid attribute " + getAttributeName(index) + ": " + e

Error message

Invalid attribute " + getAttributeName(index) + ": " + e

What it means

getAttributeBytesHex(index) converts an attribute value from a hexadecimal string to a byte array using HexDump.hexStringToByteArray. If the attribute text is not a valid hex string (odd length or non-hex characters) the conversion throws and is rewrapped as an XmlPullParserException naming the offending attribute. It indicates malformed data content, not a parser position problem.

Source

Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/XmlUtils.java:111

            return (TypedXmlSerializer) xml;
        } else {
            return new ForcedTypedXmlSerializer(xml);
        }
    }

    private static class ForcedTypedXmlPullParser extends XmlPullParserWrapper
            implements TypedXmlPullParser {
        public ForcedTypedXmlPullParser(XmlPullParser wrapped) {
            super(wrapped);
        }

        @Override
        public byte[] getAttributeBytesHex(int index)
                throws XmlPullParserException {
            try {
                return HexDump.hexStringToByteArray(getAttributeValue(index));
            } catch (Exception e) {
                throw new XmlPullParserException(
                        "Invalid attribute " + getAttributeName(index) + ": " + e);
            }
        }

        @Override
        public byte[] getAttributeBytesBase64(int index)
                throws XmlPullParserException {
            try {
                return Base64.decode(getAttributeValue(index), Base64.NO_WRAP);
            } catch (Exception e) {
                throw new XmlPullParserException(
                        "Invalid attribute " + getAttributeName(index) + ": " + e);
            }
        }

        @Override
        public int getAttributeInt(int index)
                throws XmlPullParserException {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Inspect the attribute value with getAttributeValue(index) and strip '0x' prefixes, whitespace, and separators like ':' or '-' before parsing.
  2. Confirm the attribute at that index is really the hex string; prefer lookup by attribute name over index to survive reordering.
  3. Fix the producing side so hex strings are always lowercase/uppercase even-length hex digits.
  4. Catch XmlPullParserException and treat the value as corrupt, falling back to a default byte array.

Example fix

// before
byte[] data = parser.getAttributeBytesHex(i); // may throw on '0xAB' or odd-length
// after
String v = parser.getAttributeValue(i);
String clean = v == null ? null : v.replaceFirst("^0x", "").replace(":", "").trim();
if (clean == null || clean.length() == 0 || clean.length() % 2 != 0 || !clean.matches("[0-9a-fA-F]+")) {
    throw new XmlPullParserException("Not a hex string: " + v);
}
byte[] data = HexDump.hexStringToByteArray(clean);
Defensive patterns

Strategy: try-catch

Validate before calling

String v = parser.getAttributeValue(i);
String clean = v == null ? "" : v.replaceFirst("^0x", "").replaceAll("[\\s:-]", "");
if (!clean.matches("([0-9a-fA-F]{2})+")) throw new IllegalArgumentException("Not even-length hex: " + v);

Try / catch

try {
    byte[] data = parser.getAttributeBytesHex(i);
} catch (XmlPullParserException e) {
    Log.w(TAG, "Corrupt hex attribute, using default");
    byte[] data = new byte[0];
}

Prevention

When it happens

Trigger: Calling getAttributeBytesHex on an attribute whose value is empty, has odd length, contains non-hex characters (e.g. '0x' prefix, whitespace, 'ZZ'), or points at the wrong index (non-string attribute such as a number).

Common situations: Hand-edited or tool-generated XML where a hex blob was truncated; values exported with a '0x' prefix by another serializer; reading an attribute by index when attribute order changed between file versions.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/5157bab2d69c0703. Report an issue: GitHub.