MuntashirAkon/AppManager · error · IllegalArgumentException
Invalid hex char '" + c + "'
Error message
Invalid hex char '" + c + "'
What it means
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.
Source
Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java:899
throw new XmlPullParserException(
"Invalid attribute " + name + ": " + valueString);
}
default:
throw new XmlPullParserException("Invalid conversion from " + type);
}
}
}
// NOTE: To support unbundled clients, we include an inlined copy
// of hex conversion logic from HexDump below
private final static char[] HEX_DIGITS =
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static int toByte(char c) {
if (c >= '0' && c <= '9') return (c - '0');
if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
throw new IllegalArgumentException("Invalid hex char '" + c + "'");
}
static String bytesToHexString(byte[] value) {
final int length = value.length;
final char[] buf = new char[length * 2];
int bufIndex = 0;
for (int i = 0; i < length; i++) {
byte b = value[i];
buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
}
return new String(buf);
}
static byte[] hexStringToBytes(String value) {
final int length = value.length();
if (length % 2 != 0) {
throw new IllegalArgumentException("Invalid hex length " + length);View on GitHub (pinned to 0152f468fc)
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.
Example fix
// before
byte[] b = parser.bytesToHexStringInput("0xAB CD"); // throws
// after
String hex = raw.replace("0x", "").replaceAll("\\s", "");
if (!hex.matches("[0-9a-fA-F]+")) throw new IllegalArgumentException("bad hex");
byte[] b = parseHex(hex); Defensive patterns
Strategy: validation
Validate before calling
boolean isHex = value != null && !value.isEmpty() && value.matches("[0-9a-fA-F]+"); Try / catch
try {
byte[] b = hexStringToBytes(value);
} catch (IllegalArgumentException e) {
// log corrupt hex attribute, skip or regenerate
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Invalid hex length " + length
- Invalid attribute " + getAttributeName(index) + ": " + e
- Invalid tag inside <set>: ${tagName}
- Invalid tag: ${tagName}
- Invalid SSAID size ${length}
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/5d4f7b543c326efd.
Report an issue: GitHub.