{"record":{"id":"5d4f7b543c326efd","repo":"MuntashirAkon/AppManager","slug":"invalid-hex-char-c","errorCode":null,"errorMessage":"Invalid hex char '\" + c + \"'","messagePattern":"Invalid hex char '\" \\+ c \\+ \"'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java","lineNumber":899,"sourceCode":"                        throw new XmlPullParserException(\n                                \"Invalid attribute \" + name + \": \" + valueString);\n                    }\n                default:\n                    throw new XmlPullParserException(\"Invalid conversion from \" + type);\n            }\n        }\n    }\n\n    // NOTE: To support unbundled clients, we include an inlined copy\n    // of hex conversion logic from HexDump below\n    private final static char[] HEX_DIGITS =\n            { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };\n\n    private static int toByte(char c) {\n        if (c >= '0' && c <= '9') return (c - '0');\n        if (c >= 'A' && c <= 'F') return (c - 'A' + 10);\n        if (c >= 'a' && c <= 'f') return (c - 'a' + 10);\n        throw new IllegalArgumentException(\"Invalid hex char '\" + c + \"'\");\n    }\n\n    static String bytesToHexString(byte[] value) {\n        final int length = value.length;\n        final char[] buf = new char[length * 2];\n        int bufIndex = 0;\n        for (int i = 0; i < length; i++) {\n            byte b = value[i];\n            buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];\n            buf[bufIndex++] = HEX_DIGITS[b & 0x0F];\n        }\n        return new String(buf);\n    }\n\n    static byte[] hexStringToBytes(String value) {\n        final int length = value.length();\n        if (length % 2 != 0) {\n            throw new IllegalArgumentException(\"Invalid hex length \" + length);","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java#L881-L917","documentation":"BinaryXmlPullParser.toByte() throws IllegalArgumentException when a character in a hex-encoded byte string is not a valid hex digit (0-9, A-F, a-f). It is used by hexStringToBytes when decoding TYPE_BYTES_HEX attributes.","triggerScenarios":"Calling hexStringToBytes() (directly or via reading a hex-bytes attribute) with a string containing characters outside [0-9a-fA-F], e.g. whitespace, 'g', '0x' prefixes, or dashes.","commonSituations":"Copy-pasted hex values with spaces or \"0x\" prefixes, corrupted stored attributes, or hex produced with uppercase/lowercase mixing that was further mangled by editing.","solutions":["Sanitize the input: strip whitespace and any \"0x\" prefix before decoding.","Validate with a regex ^[0-9a-fA-F]+$ before calling.","Regenerate the attribute from the original bytes if the stored value is corrupted.","Catch IllegalArgumentException around hexStringToBytes and report/recover."],"exampleFix":"// before\nbyte[] b = parser.bytesToHexStringInput(\"0xAB CD\"); // throws\n// after\nString hex = raw.replace(\"0x\", \"\").replaceAll(\"\\\\s\", \"\");\nif (!hex.matches(\"[0-9a-fA-F]+\")) throw new IllegalArgumentException(\"bad hex\");\nbyte[] b = parseHex(hex);","handlingStrategy":"validation","validationCode":"boolean isHex = value != null && !value.isEmpty() && value.matches(\"[0-9a-fA-F]+\");","typeGuard":null,"tryCatchPattern":"try {\n    byte[] b = hexStringToBytes(value);\n} catch (IllegalArgumentException e) {\n    // log corrupt hex attribute, skip or regenerate\n}","preventionTips":["Strip \"0x\" prefixes and whitespace before decoding hex.","Always generate hex via bytesToHexString instead of hand-rolling.","Regex-validate hex strings at input boundaries.","Never splice or trim hex strings blindly (odd-length results)."],"tags":["xml","hex","decoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}