apache/flink · error · IllegalArgumentException

The block size parameter must be set and larger than 0.

Error message

The block size parameter must be set and larger than 0.

What it means

BinaryInputFormat (base of binary block input formats) requires a block size that is either the sentinel NATIVE_BLOCK_SIZE (Long.MIN_VALUE, meaning 'use the filesystem's native block size') or a strictly positive value. setBlockSize throws IllegalArgumentException for any value < 1 that is not the native sentinel, because a non-positive real block size cannot delimit records or align splits.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/BinaryInputFormat.java:89

    private transient BlockInfo blockInfo;

    /** A wrapper around the block currently being read. */
    private transient BlockBasedInput blockBasedInput = null;

    /**
     * The number of records already read from the block. This is used to decide if the end of the
     * block has been reached.
     */
    private long readRecords = 0;

    @Override
    public void configure(Configuration parameters) {
        super.configure(parameters);
    }

    public void setBlockSize(long blockSize) {
        if (blockSize < 1 && blockSize != NATIVE_BLOCK_SIZE) {
            throw new IllegalArgumentException(
                    "The block size parameter must be set and larger than 0.");
        }
        if (blockSize > Integer.MAX_VALUE) {
            throw new UnsupportedOperationException(
                    "Currently only block sizes up to Integer.MAX_VALUE are supported");
        }
        this.blockSize = blockSize;
    }

    public long getBlockSize() {
        return this.blockSize;
    }

    @Override
    public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {
        final List<FileStatus> files = this.getFiles();

        final List<FileInputSplit> inputSplits = new ArrayList<FileInputSplit>(minNumSplits);

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Pass a positive block size (e.g. format.setBlockSize(128 * 1024 * 1024) for 128 MB).
  2. Pass BinaryInputFormat.NATIVE_BLOCK_SIZE to let the format use the HDFS/filesystem native block size.
  3. Validate the computed block size is >= 1 (or == NATIVE_BLOCK_SIZE) before calling setBlockSize.

Example fix

// before
format.setBlockSize(configuredBlockSize); // configuredBlockSize == 0 -> throws

// after
long bs = configuredBlockSize > 0 ? configuredBlockSize : BinaryInputFormat.NATIVE_BLOCK_SIZE;
format.setBlockSize(bs);
Defensive patterns

Strategy: validation

Validate before calling

long bs = configuredBlockSize;
if (bs != BinaryInputFormat.NATIVE_BLOCK_SIZE && bs < 1) {
    throw new IllegalArgumentException("block size must be > 0 or NATIVE_BLOCK_SIZE, got " + bs);
}
format.setBlockSize(bs);

Prevention

When it happens

Trigger: Calling format.setBlockSize(0), format.setBlockSize(-1), or any negative value other than BinaryInputFormat.NATIVE_BLOCK_SIZE. Passing a value parsed/misconfigured from user input that defaulted to 0.

Common situations: Configuring a BinaryInputFormat subclass (e.g. for a custom binary file format) with a block size read from a property that was unset and defaulted to 0; arithmetic that computes block size from a file size and underflows to <= 0.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/4049e076ee63c21e. Report an issue: GitHub.