zxing/zxing · error · IllegalArgumentException
Illegal contents
Error message
Illegal contents
What it means
Error "Illegal contents" thrown in zxing/zxing.
Source
Thrown at core/src/main/java/com/google/zxing/oned/UPCEWriter.java:62
int length = contents.length();
switch (length) {
case 7:
// No check digit present, calculate it and add it
int check;
try {
check = UPCEANReader.getStandardUPCEANChecksum(UPCEReader.convertUPCEtoUPCA(contents));
} catch (FormatException fe) {
throw new IllegalArgumentException(fe);
}
contents += check;
break;
case 8:
try {
if (!UPCEANReader.checkStandardUPCEANChecksum(UPCEReader.convertUPCEtoUPCA(contents))) {
throw new IllegalArgumentException("Contents do not pass checksum");
}
} catch (FormatException ignored) {
throw new IllegalArgumentException("Illegal contents");
}
break;
default:
throw new IllegalArgumentException(
"Requested contents should be 7 or 8 digits long, but got " + length);
}
checkNumeric(contents);
int firstDigit = Character.digit(contents.charAt(0), 10);
if (firstDigit != 0 && firstDigit != 1) {
throw new IllegalArgumentException("Number system must be 0 or 1");
}
int checkDigit = Character.digit(contents.charAt(7), 10);
int parities = UPCEReader.NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkDigit];
boolean[] result = new boolean[CODE_WIDTH];
View on GitHub (pinned to 19aa2d8254)
Solutions
- Supply numeric contents of valid length for UPC-E encoding.
- Sanitize the input to remove characters that are not digits.
When it happens
Trigger: Thrown at core/src/main/java/com/google/zxing/oned/UPCEWriter.java:62 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zxing/zxing@19aa2d8254 (2026-08-14).
Data as JSON: /api/errors/a10a2ca59b75aa5f.
Report an issue: GitHub.