{"record":{"id":"f713127be1008474","repo":"apache/cassandra","slug":"invalid-64-bits-long-value-expecting-8-bytes-but","errorCode":null,"errorMessage":"Invalid 64-bits long value, expecting 8 bytes but got ","messagePattern":"Invalid 64-bits long value, expecting 8 bytes but got ","errorType":"validation","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java","lineNumber":1110,"sourceCode":"        {\n            if (value == null) return \"NULL\";\n            return Long.toString(value);\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(long value, ProtocolVersion protocolVersion)\n        {\n            ByteBuffer bb = ByteBuffer.allocate(8);\n            bb.putLong(0, value);\n            return bb;\n        }\n\n        @Override\n        public long deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion)\n        {\n            if (bytes == null || bytes.remaining() == 0) return 0;\n            if (bytes.remaining() != 8)\n                throw new InvalidTypeException(\n                \"Invalid 64-bits long value, expecting 8 bytes but got \" + bytes.remaining());\n\n            return bytes.getLong(bytes.position());\n        }\n    }\n\n    /**\n     * This codec maps a CQL {@link DataType#bigint()} to a Java {@link Long}.\n     */\n    private static class BigintCodec extends LongCodec\n    {\n\n        private static final BigintCodec instance = new BigintCodec();\n\n        private BigintCodec()\n        {\n            super(DataType.bigint());\n        }","sourceCodeStart":1092,"sourceCodeEnd":1128,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1092-L1128","documentation":"The bigint codec's deserializeNoBoxing() requires exactly 8 bytes on the wire, matching CQL's fixed 8-byte bigint encoding. A buffer with a different remaining size means the bytes are not a bigint value — usually the wrong codec was applied to the column's bytes.","triggerScenarios":"Calling bigintCodec.deserializeNoBoxing(bytes, protocolVersion) (or deserialize/get on a Row with a bigint codec) where bytes.remaining() is 0 handled earlier but 1..7 or 9+ here — e.g. an int (4-byte) or varint column decoded as bigint.","commonSituations":"Schema changed from int to bigint (or vice versa) while cached codecs/prepared statements still assume the old width; manual byte assembly with ByteBuffer.putInt instead of putLong; reading a counter/varint column through the wrong codec.","solutions":["Use the codec matching the column's declared type (int codec for 4-byte, bigint for 8-byte, varint for BigInteger).","Fix the byte production side to emit exactly 8 bytes: ByteBuffer.allocate(8).putLong(value).","Refresh prepared statements/codecs after any ALTER TABLE type change.","If length is genuinely variable, the column is varint — switch to the bigInteger codec."],"exampleFix":"// before\nByteBuffer b = ByteBuffer.allocate(4).putInt(42);\nlongCodec.deserializeNoBoxing(b, version); // throws: got 4 bytes\n// after\nByteBuffer b = ByteBuffer.allocate(8).putLong(42L);\nlongCodec.deserializeNoBoxing(b, version); // 42","handlingStrategy":"type-guard","validationCode":"if (bytes == null || bytes.remaining() != 8)\n    throw new IllegalArgumentException(\"bigint needs exactly 8 bytes, got \" + (bytes == null ? 0 : bytes.remaining()));","typeGuard":"boolean isBigintBuffer(ByteBuffer b) {\n    return b != null && b.remaining() == 8;\n}","tryCatchPattern":"try {\n    return longCodec.deserializeNoBoxing(bytes, protocolVersion);\n} catch (InvalidTypeException e) {\n    // wrong codec or corrupt bytes; fall back to the declared column type\n    return intCodec == null ? 0L : intCodec.deserializeNoBoxing(bytes, protocolVersion);\n}","preventionTips":["Always serialize with the same codec you deserialize with; avoid hand-rolled putInt for bigint values.","Re-prepare statements after ALTER TABLE type changes.","Duplicate and position buffers correctly so remaining() reflects only the value bytes."],"tags":["cql","bigint","codec","deserialization","byte-size"],"backgroundTag":"shape-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}