{"record":{"id":"a24be8b56c0cfaa8","repo":"prestodb/presto","slug":"blocks-is-empty","errorCode":null,"errorMessage":"blocks is empty","messagePattern":"blocks is empty","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/Page.java","lineNumber":375,"sourceCode":"        return wrapBlocksWithoutCopy(positionCount, blocks);\n    }\n\n    @Override\n    public String toString()\n    {\n        StringBuilder builder = new StringBuilder(\"Page{\");\n        builder.append(\"positions=\").append(positionCount);\n        builder.append(\", channels=\").append(getChannelCount());\n        builder.append('}');\n        builder.append(\"@\").append(Integer.toHexString(System.identityHashCode(this)));\n        return builder.toString();\n    }\n\n    private static int determinePositionCount(Block... blocks)\n    {\n        requireNonNull(blocks, \"blocks is null\");\n        if (blocks.length == 0) {\n            throw new IllegalArgumentException(\"blocks is empty\");\n        }\n\n        return blocks[0].getPositionCount();\n    }\n\n    public Page getPositions(int[] retainedPositions, int offset, int length)\n    {\n        requireNonNull(retainedPositions, \"retainedPositions is null\");\n\n        Block[] blocks = new Block[this.blocks.length];\n        for (int i = 0; i < blocks.length; i++) {\n            blocks[i] = this.blocks[i].getPositions(retainedPositions, offset, length);\n        }\n        return wrapBlocksWithoutCopy(length, blocks);\n    }\n\n    public Page copyPositions(int[] retainedPositions, int offset, int length)\n    {","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/Page.java#L357-L393","documentation":"Page's constructor requires at least one Block because positionCount is derived from the first block (determinePositionCount). Constructing a Page with zero blocks is meaningless (no channel to determine row count from), so the library throws IllegalArgumentException.","triggerScenarios":"new Page() with an empty Block[] or no arguments — e.g. building a page from an empty list of columns, or a connector that returns zero output channels.","commonSituations":"Dynamic column projection that can produce zero columns; aggregation code that builds a page only from optional columns; bugs where a single-column page's only block was removed.","solutions":["Ensure at least one block (e.g. a constant or row-number block) is always included in the page","If a zero-column result is legitimate, use a different representation (e.g. a page with a constant 'true' marker block)","Fix the projection logic so it never passes an empty blocks array to the Page constructor"],"exampleFix":"// before\nPage page = new Page(); // throws\n// after\nif (blocks.length == 0) {\n    blocks = new Block[]{new RunLengthEncodedBlock(TRUE_CONSTANT, 0)};\n}\nPage page = new Page(blocks);","handlingStrategy":"validation","validationCode":"if (blocks == null || blocks.length == 0) {\n    throw new IllegalArgumentException(\"cannot construct Page with zero blocks\");\n}\nPage page = new Page(blocks);","typeGuard":"boolean canBuildPage(Block[] blocks) {\n    return blocks != null && blocks.length > 0;\n}","tryCatchPattern":"try {\n    page = new Page(blocks);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"blocks is empty\")) throw e;\n    page = new Page(RunLengthEncodedBlock.TRUE_CONSTANT_BLOCK, 0); // or skip operator\n}","preventionTips":["Assert block arrays non-empty at operator boundaries","Always emit at least one marker column for zero-column relations","Test connectors with empty projection lists"],"tags":["presto","page-constructor","empty-input","illegal-argument"],"backgroundTag":"empty-block-list","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}