{"record":{"id":"72a3a423db1274fe","repo":"prestodb/presto","slug":"expected-entry-size-to-be-exactly-int128-byte","errorCode":null,"errorMessage":"\"Expected entry size to be exactly \" + INT128_BYTES + \" bytes but was \" + (entryPositionCount * SIZE_OF_LONG)","messagePattern":"\"Expected entry size to be exactly \" \\+ INT128_BYTES \\+ \" bytes but was \" \\+ \\(entryPositionCount \\* SIZE_OF_LONG\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlockBuilder.java","lineNumber":89,"sourceCode":"    @Override\n    public BlockBuilder writeLong(long value)\n    {\n        if (valueIsNull.length <= positionCount) {\n            growCapacity();\n        }\n\n        values[(positionCount * 2) + entryPositionCount] = value;\n        entryPositionCount++;\n\n        hasNonNullValue = true;\n        return this;\n    }\n\n    @Override\n    public BlockBuilder closeEntry()\n    {\n        if (entryPositionCount != 2) {\n            throw new IllegalStateException(\"Expected entry size to be exactly \" + INT128_BYTES + \" bytes but was \" + (entryPositionCount * SIZE_OF_LONG));\n        }\n\n        positionCount++;\n        entryPositionCount = 0;\n        if (blockBuilderStatus != null) {\n            blockBuilderStatus.addBytes(Byte.BYTES + INT128_BYTES);\n        }\n        return this;\n    }\n\n    @Override\n    public BlockBuilder appendNull()\n    {\n        if (valueIsNull.length <= positionCount) {\n            growCapacity();\n        }\n        if (entryPositionCount != 0) {\n            throw new IllegalStateException(\"Current entry must be closed before a null can be written\");","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/Int128ArrayBlockBuilder.java#L71-L107","documentation":"Int128ArrayBuilder writes each 128-bit entry as exactly 2 longs (16 bytes) before closeEntry seals it. If entryPositionCount != 2 at closeEntry time, the entry is incomplete (not exactly 16 bytes written), so IllegalStateException is thrown to prevent writing a corrupt value into the block.","triggerScenarios":"Calling closeEntry() on Int128ArrayBuilder after writing fewer or more than 2 longs — e.g. writing only writeLong(value, 0) without the high part, calling closeEntry twice, or a buildLongs-style loop writing one long per entry for DECIMAL(38,x).","commonSituations":"Generic BlockBuilder code treating INT128 like BIGINT (one writeLong then closeEntry); reset/abort paths that leave entryPositionCount in a partial state; decimal writers with wrong precision dispatch (writing 1 long for a 38-digit decimal).","solutions":["For each entry write both halves: builder.writeLong(low, 0); builder.writeLong(high, 1); then closeEntry().","Ensure the writer dispatches by type precision — use Int128ArrayBuilder only for values needing 16 bytes (DECIMAL(38,x)); long decimals use BigintArrayBuilder.","If an entry was partially written, call resetToCurrentSize/producePage correctly instead of closeEntry; do not call closeEntry twice."],"exampleFix":"// before\nbuilder.writeLong(value); // only 8 bytes\nbuilder.closeEntry(); // throws\n// after\nbuilder.writeLong(low64, 0);\nbuilder.writeLong(high64, 1);\nbuilder.closeEntry();","handlingStrategy":"validation","validationCode":"// before closing, ensure exactly 16 bytes (2 longs) were written for the entry\n// Int128ArrayBuilder tracks entryPositionCount internally; write both halves first\nbuilder.writeLong(low, 0);\nbuilder.writeLong(high, 1);\nbuilder.closeEntry();","typeGuard":"boolean entryFullyWritten(int entryPositionCount) { return entryPositionCount == 2; } // 2 longs = 16 bytes","tryCatchPattern":"try {\n    builder.closeEntry();\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Expected entry size to be exactly\")) {\n        throw new IllegalStateException(\"INT128 entry incomplete: write both 64-bit halves before closeEntry\", e);\n    }\n    throw e;\n}","preventionTips":["Always pair writeLong(low, 0) with writeLong(high, 1) for INT128 entries.","Dispatch writers by decimal precision: 16-byte entries only for DECIMAL(p,x) with p > 18.","Never call closeEntry twice or after an aborted partial write; use the builder's reset/rollback APIs."],"tags":["presto","block-builder","int128","incomplete-entry"],"backgroundTag":"incomplete-entry-close","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"}