apache/hadoop · error · IllegalArgumentException

blockSize({}) < 1

Error message

blockSize({}) < 1

What it means

CBZip2OutputStream's constructor validates the blockSize argument, which selects the compression block size as blockSize * 100000 bytes and must be within MIN_BLOCKSIZE(1)..MAX_BLOCKSIZE(9). A value below 1 is rejected immediately with IllegalArgumentException("blockSize(...) < 1"). This is a pure API-misuse guard: the compressor cannot be built with a non-positive block size.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/compress/bzip2/CBZip2OutputStream.java:632

  * @param blockSize
  *            the blockSize as 100k units.
  *
  * @throws IOException
  *             if an I/O error occurs in the specified stream.
  * @throws IllegalArgumentException
  *             if {@code (blockSize < 1) || (blockSize > 9)}
  * @throws NullPointerException
  *             if {@code out == null}.
  *
  * @see #MIN_BLOCKSIZE
  * @see #MAX_BLOCKSIZE
  */
  public CBZip2OutputStream(final OutputStream out, final int blockSize)
      throws IOException {
    super();

    if (blockSize < 1) {
      throw new IllegalArgumentException("blockSize(" + blockSize
          + ") < 1");
    }
    if (blockSize > 9) {
      throw new IllegalArgumentException("blockSize(" + blockSize
          + ") > 9");
    }

    this.blockSize100k = blockSize;
    this.out = out;
    init();
  }

  @Override
  public void write(final int b) throws IOException {
    if (this.out != null) {
      write0(b);
    } else {
      throw new IOException("closed");

View on GitHub (pinned to 2add963021)

Solutions

  1. Clamp the value to the documented range before constructing: Math.max(CBZip2OutputStream.MIN_BLOCKSIZE, Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, blockSize)).
  2. If deriving from Configuration, use a sane default (Bzip2Factory reads 'bzip2.compress.blocksize', defaulting to 9) and validate the parsed integer.
  3. Consider the built-in helper CBZip2OutputStream.chooseBlockSize(inputLength) which returns a legal value for a given input size.
  4. Fail fast with a clear config error message naming the offending property and value.

Example fix

// before
int bs = conf.getInt("bzip2.compress.blocksize", 0);
new CBZip2OutputStream(out, bs); // IllegalArgumentException: blockSize(0) < 1

// after
int bs = conf.getInt("bzip2.compress.blocksize",
                      CBZip2OutputStream.MAX_BLOCKSIZE);
bs = Math.max(CBZip2OutputStream.MIN_BLOCKSIZE,
       Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, bs));
new CBZip2OutputStream(out, bs);
Defensive patterns

Strategy: validation

Validate before calling

int bs = Math.max(CBZip2OutputStream.MIN_BLOCKSIZE,
                  Math.min(CBZip2OutputStream.MAX_BLOCKSIZE, requested));
new CBZip2OutputStream(out, bs);

Prevention

When it happens

Trigger: new CBZip2OutputStream(out, blockSize) called with 0 or a negative number: a Configuration property parsed to 0 (e.g. 'bzip2.compress.blocksize' unset returning a bad default in caller code), a computed value underflowing, or a literal mistake.

Common situations: Block size read from job/config XML where a missing key was defaulted to 0 by hand-rolled getInt code; values derived from user input or arithmetic (size/100000 with small inputs) going negative; porting code that assumed a different blockSize unit (900000 vs 9).

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/3d23d2bf0e26df0f. Report an issue: GitHub.