{"record":{"id":"d97d443ffcce51c2","repo":"apache/cassandra","slug":"invalid-64-bits-double-value-expecting-8-bytes-bu","errorCode":null,"errorMessage":"Invalid 64-bits double value, expecting 8 bytes but got ","messagePattern":"Invalid 64-bits double 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":1410,"sourceCode":"        {\n            if (value == null) return \"NULL\";\n            return Double.toString(value);\n        }\n\n        @Override\n        public ByteBuffer serializeNoBoxing(double value, ProtocolVersion protocolVersion)\n        {\n            ByteBuffer bb = ByteBuffer.allocate(8);\n            bb.putDouble(0, value);\n            return bb;\n        }\n\n        @Override\n        public double 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 double value, expecting 8 bytes but got \" + bytes.remaining());\n\n            return bytes.getDouble(bytes.position());\n        }\n    }\n\n    /**\n     * This codec maps a CQL {@link DataType#cfloat()} to a Java {@link Float}.\n     */\n    private static class FloatCodec extends PrimitiveFloatCodec\n    {\n\n        private static final FloatCodec instance = new FloatCodec();\n\n        private FloatCodec()\n        {\n            super(DataType.cfloat());\n        }","sourceCodeStart":1392,"sourceCodeEnd":1428,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java#L1392-L1428","documentation":"Thrown by the DoubleCodec's deserializeNoBoxing when the incoming ByteBuffer does not contain exactly 8 bytes, the wire size of a CQL double. A null or empty buffer deserializes to 0, but any other non-8-byte length is invalid and cannot be interpreted as a 64-bit IEEE-754 double.","triggerScenarios":"Calling codec.deserializeNoBoxing(bytes, protocolVersion) (or deserialize) with a ByteBuffer whose remaining() is 1-7 or 9+ bytes, typically when reading a column that is not actually a double, or a truncated/corrupt value.","commonSituations":"Reading a column whose CQL type changed (e.g. float stored where double expected), manually slicing a composite/legacy payload at wrong offsets, or hand-rolled collection/UDT parsing that mis-sizes element buffers.","solutions":["Verify the column's CQL type matches double before deserializing (row.getColumnDefinitions().getType(i)).","Check that the ByteBuffer passed in is exactly 8 bytes: log bytes.remaining() and the buffer's hex dump.","If reading from a collection or UDT, use the provided collection codecs rather than manual slicing so element boundaries are honored.","Re-read from the source with the correct type codec (e.g. FloatCodec for a 4-byte value)."],"exampleFix":"// before\nfloat f = codecFor(Double.class).deserializeNoBoxing(buffer, ProtocolVersion.V4);\n// after\nDataType colType = row.getColumnDefinitions().getType(\"my_col\");\nif (colType == DataType.doublePrecision()) {\n    double d = row.getDouble(\"my_col\");\n} else if (colType == DataType.cfloat()) {\n    float f = row.getFloat(\"my_col\");\n}","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.remaining() == 0) return 0d;\nif (bytes.remaining() != 8)\n    throw new IllegalArgumentException(\"Expected 8 bytes for double, got \" + bytes.remaining());","typeGuard":"boolean isDoubleSized(ByteBuffer b) { return b != null && b.remaining() == 8; }","tryCatchPattern":"try { return codec.deserializeNoBoxing(bytes, protocolVersion); }\ncatch (InvalidTypeException e) {\n    log.warn(\"Double deserialization failed: {} (remaining={})\", e.getMessage(), bytes.remaining());\n    return 0d;\n}","preventionTips":["Check DataType of the column before choosing a codec.","Prefer row typed getters over manual codec calls.","Never slice raw collection/UDT buffers by hand; use collection codecs.","Log remaining() bytes on any InvalidTypeException to diagnose width mismatch."],"tags":["serialization","bytebuffer","type-codec","deserialization"],"backgroundTag":"type-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"}