Troubleshoot Complex Barcodes
Troubleshoot Complex Barcodes
Complex barcode problems can occur at different stages: image recognition, standardized text decoding, required-field validation, or standard-specific range validation. Diagnosing the correct stage avoids misleading fixes.
The complete source code for this article is available on GitHub:
View ComplexBarcodeTroubleshooting.java
Barcode image is not recognized
A blank or damaged image produces no results:
BarCodeReader reader = new BarCodeReader(
outputPath,
DecodeType.ALL_SUPPORTED_TYPES
);
BarCodeResult[] results =
reader.readBarCodes();
Assert.assertEquals(results.length, 0);
This is an image-recognition problem rather than a complex codetext problem. Check image quality, contrast, quiet zones, scaling, and the selected carrier type.
Recognized text cannot be decoded
A carrier can be recognized while its text is invalid for the requested complex format:
String invalidCodetext =
"NOT-A-COMPLEX-BARCODE";
Assert.assertNull(
ComplexCodetextReader.tryDecodeSwissQR(
invalidCodetext
)
);
The tryDecode... methods return null for unsupported data.
Required fields are missing
Constructing codetext can raise BarCodeException when required data is absent:
SwissQRCodetext incomplete =
new SwissQRCodetext();
try {
incomplete.getConstructedCodetext();
} catch (BarCodeException exception) {
// Inspect the validation message.
}
For Swiss QR, a missing or invalid IBAN is one possible cause.
Data violates a standard limit
The API validates standard-specific ranges before generation:
MailmarkCodetext invalid =
new MailmarkCodetext();
invalid.setItemID(100_000_000);
An out-of-range Mailmark item identifier causes BarCodeException during codetext construction.
Use a staged diagnostic workflow
Check failures in this order:
- verify that the image exists and is readable;
- recognize the carrier barcode;
- confirm the recognized
DecodeType; - inspect the recognized text;
- call the matching complex decoder;
- validate required decoded fields.
Recommendations
- Do not treat an empty recognition result as a decoding failure.
- Check for
nullfromtryDecode...methods. - Validate required fields before generation.
- Catch
BarCodeExceptionaround codetext construction. - Include standard-limit cases in automated tests.
- Log carrier type and recognized text when diagnosing failures.