zxing/zxing · error · IllegalArgumentException

Found empty contents

Error message

Found empty contents

What it means

Error "Found empty contents" thrown in zxing/zxing.

Source

Thrown at core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java:55

  private static final int QUIET_ZONE_SIZE = 4;

  @Override
  public BitMatrix encode(String contents, BarcodeFormat format, int width, int height)
      throws WriterException {

    return encode(contents, format, width, height, null);
  }

  @Override
  public BitMatrix encode(String contents,
                          BarcodeFormat format,
                          int width,
                          int height,
                          Map<EncodeHintType,?> hints) throws WriterException {

    if (contents.isEmpty()) {
      throw new IllegalArgumentException("Found empty contents");
    }

    if (format != BarcodeFormat.QR_CODE) {
      throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
    }

    if (width < 0 || height < 0) {
      throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
          height);
    }

    ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
    int quietZone = QUIET_ZONE_SIZE;
    if (hints != null) {
      if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
        errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
      }
      if (hints.containsKey(EncodeHintType.MARGIN)) {

View on GitHub (pinned to 19aa2d8254)

Solutions

  1. Pass non-empty contents to QRCodeWriter.encode().
  2. Check the input for null/empty before invoking the writer.

When it happens

Trigger: Thrown at core/src/main/java/com/google/zxing/qrcode/QRCodeWriter.java:55 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/1cf25729567578f7. Report an issue: GitHub.