{"record":{"id":"5157bab2d69c0703","repo":"MuntashirAkon/AppManager","slug":"invalid-attribute-getattributename-index-e","errorCode":null,"errorMessage":"Invalid attribute \" + getAttributeName(index) + \": \" + e","messagePattern":"Invalid attribute \" \\+ getAttributeName\\(index\\) \\+ \": \" \\+ e","errorType":"exception","errorClass":"XmlPullParserException","httpStatus":null,"severity":"error","filePath":"libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/XmlUtils.java","lineNumber":111,"sourceCode":"            return (TypedXmlSerializer) xml;\n        } else {\n            return new ForcedTypedXmlSerializer(xml);\n        }\n    }\n\n    private static class ForcedTypedXmlPullParser extends XmlPullParserWrapper\n            implements TypedXmlPullParser {\n        public ForcedTypedXmlPullParser(XmlPullParser wrapped) {\n            super(wrapped);\n        }\n\n        @Override\n        public byte[] getAttributeBytesHex(int index)\n                throws XmlPullParserException {\n            try {\n                return HexDump.hexStringToByteArray(getAttributeValue(index));\n            } catch (Exception e) {\n                throw new XmlPullParserException(\n                        \"Invalid attribute \" + getAttributeName(index) + \": \" + e);\n            }\n        }\n\n        @Override\n        public byte[] getAttributeBytesBase64(int index)\n                throws XmlPullParserException {\n            try {\n                return Base64.decode(getAttributeValue(index), Base64.NO_WRAP);\n            } catch (Exception e) {\n                throw new XmlPullParserException(\n                        \"Invalid attribute \" + getAttributeName(index) + \": \" + e);\n            }\n        }\n\n        @Override\n        public int getAttributeInt(int index)\n                throws XmlPullParserException {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/XmlUtils.java#L93-L129","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Inspect the attribute value with getAttributeValue(index) and strip '0x' prefixes, whitespace, and separators like ':' or '-' before parsing.","Confirm the attribute at that index is really the hex string; prefer lookup by attribute name over index to survive reordering.","Fix the producing side so hex strings are always lowercase/uppercase even-length hex digits.","Catch XmlPullParserException and treat the value as corrupt, falling back to a default byte array."],"exampleFix":"// before\nbyte[] data = parser.getAttributeBytesHex(i); // may throw on '0xAB' or odd-length\n// after\nString v = parser.getAttributeValue(i);\nString clean = v == null ? null : v.replaceFirst(\"^0x\", \"\").replace(\":\", \"\").trim();\nif (clean == null || clean.length() == 0 || clean.length() % 2 != 0 || !clean.matches(\"[0-9a-fA-F]+\")) {\n    throw new XmlPullParserException(\"Not a hex string: \" + v);\n}\nbyte[] data = HexDump.hexStringToByteArray(clean);","handlingStrategy":"try-catch","validationCode":"String v = parser.getAttributeValue(i);\nString clean = v == null ? \"\" : v.replaceFirst(\"^0x\", \"\").replaceAll(\"[\\\\s:-]\", \"\");\nif (!clean.matches(\"([0-9a-fA-F]{2})+\")) throw new IllegalArgumentException(\"Not even-length hex: \" + v);","typeGuard":null,"tryCatchPattern":"try {\n    byte[] data = parser.getAttributeBytesHex(i);\n} catch (XmlPullParserException e) {\n    Log.w(TAG, \"Corrupt hex attribute, using default\");\n    byte[] data = new byte[0];\n}","preventionTips":["Look up attributes by name, not index, to survive attribute reordering.","Normalize hex (strip 0x, separators, whitespace) at the producer side.","Pre-validate with a hex regex before parsing."],"tags":["xml","hex","attribute-parsing"],"backgroundTag":"invalid-attribute-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}