{"record":{"id":"4049e076ee63c21e","repo":"apache/flink","slug":"the-block-size-parameter-must-be-set-and-larger-th","errorCode":null,"errorMessage":"The block size parameter must be set and larger than 0.","messagePattern":"The block size parameter must be set and larger than 0\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/BinaryInputFormat.java","lineNumber":89,"sourceCode":"    private transient BlockInfo blockInfo;\n\n    /** A wrapper around the block currently being read. */\n    private transient BlockBasedInput blockBasedInput = null;\n\n    /**\n     * The number of records already read from the block. This is used to decide if the end of the\n     * block has been reached.\n     */\n    private long readRecords = 0;\n\n    @Override\n    public void configure(Configuration parameters) {\n        super.configure(parameters);\n    }\n\n    public void setBlockSize(long blockSize) {\n        if (blockSize < 1 && blockSize != NATIVE_BLOCK_SIZE) {\n            throw new IllegalArgumentException(\n                    \"The block size parameter must be set and larger than 0.\");\n        }\n        if (blockSize > Integer.MAX_VALUE) {\n            throw new UnsupportedOperationException(\n                    \"Currently only block sizes up to Integer.MAX_VALUE are supported\");\n        }\n        this.blockSize = blockSize;\n    }\n\n    public long getBlockSize() {\n        return this.blockSize;\n    }\n\n    @Override\n    public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {\n        final List<FileStatus> files = this.getFiles();\n\n        final List<FileInputSplit> inputSplits = new ArrayList<FileInputSplit>(minNumSplits);","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/BinaryInputFormat.java#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a positive block size (e.g. format.setBlockSize(128 * 1024 * 1024) for 128 MB).","Pass BinaryInputFormat.NATIVE_BLOCK_SIZE to let the format use the HDFS/filesystem native block size.","Validate the computed block size is >= 1 (or == NATIVE_BLOCK_SIZE) before calling setBlockSize."],"exampleFix":"// before\nformat.setBlockSize(configuredBlockSize); // configuredBlockSize == 0 -> throws\n\n// after\nlong bs = configuredBlockSize > 0 ? configuredBlockSize : BinaryInputFormat.NATIVE_BLOCK_SIZE;\nformat.setBlockSize(bs);","handlingStrategy":"validation","validationCode":"long bs = configuredBlockSize;\nif (bs != BinaryInputFormat.NATIVE_BLOCK_SIZE && bs < 1) {\n    throw new IllegalArgumentException(\"block size must be > 0 or NATIVE_BLOCK_SIZE, got \" + bs);\n}\nformat.setBlockSize(bs);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat 0/negative as 'use native' by mapping to BinaryInputFormat.NATIVE_BLOCK_SIZE.","Validate computed block sizes before setBlockSize.","Document that NATIVE_BLOCK_SIZE == Long.MIN_VALUE is the only allowed non-positive sentinel."],"tags":["input-format","binary","block-size","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}