{"record":{"id":"32088e6fc3f2b59b","repo":"apache/cassandra","slug":"expected-8-or-0-byte-value-for-a-double-d","errorCode":null,"errorMessage":"Expected 8 or 0 byte value for a double (%d)","messagePattern":"Expected 8 or 0 byte value for a double \\((.+?)\\)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/DoubleSerializer.java","lineNumber":45,"sourceCode":"{\n    public static final DoubleSerializer instance = new DoubleSerializer();\n\n    public <V> Double deserialize(V value, ValueAccessor<V> accessor)\n    {\n        if (accessor.isEmpty(value))\n            return null;\n        return accessor.toDouble(value);\n    }\n\n    public ByteBuffer serialize(Double value)\n    {\n        return (value == null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER : ByteBufferUtil.bytes(value);\n    }\n\n    public <T> void validate(T value, ValueAccessor<T> accessor) throws MarshalException\n    {\n        if (accessor.size(value) != 8 && !accessor.isEmpty(value))\n            throw new MarshalException(String.format(\"Expected 8 or 0 byte value for a double (%d)\", accessor.size(value)));\n    }\n\n    public String toString(Double value)\n    {\n        return value == null ? \"\" : value.toString();\n    }\n\n    public Class<Double> getType()\n    {\n        return Double.class;\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/DoubleSerializer.java#L27-L58","documentation":"MarshalException raised by DoubleSerializer.validate when a serialized double value on disk or on the wire is neither empty (null) nor exactly 8 bytes long. The input is corrupt or was produced by an incompatible writer, since a double always serializes to 8 bytes.","triggerScenarios":"validate/deserialize on a buffer that is non-empty but not 8 bytes — e.g. a float (4 bytes) or int written into a double column, truncated cell data, or wrong type in a collection of doubles.","commonSituations":"Inserting Float into a double column via custom serialization; schema type mismatch after ALTER; partial writes/corruption; UDF returning wrong-width bytes.","solutions":["Serialize with DoubleSerializer.serialize(Double) so exactly 8 bytes are written","Fix type mismatch: cast to double before writing, or correct the column type","Convert 4-byte float data by reading as float and re-serializing as double","If truncated on disk, restore/repair the data"],"exampleFix":"// before\nByteBuffer bad = ByteBuffer.allocate(4).putFloat(1.5f);\n// after\nByteBuffer ok = DoubleSerializer.instance.serialize(Double.valueOf(1.5d));","handlingStrategy":"type-guard","validationCode":"public static void checkDouble(ByteBuffer buf) {\n    if (buf != null && buf.hasRemaining() && buf.remaining() != 8)\n        throw new MarshalException(\"double must be 8 bytes, got \" + buf.remaining());\n}","typeGuard":"public static boolean isDoubleSized(ByteBuffer buf) {\n    return buf == null || !buf.hasRemaining() || buf.remaining() == 8;\n}","tryCatchPattern":"try {\n    Double d = DoubleSerializer.instance.deserialize(buffer);\n} catch (MarshalException e) {\n    logger.warn(\"Bad double value: {}\", e.getMessage());\n}","preventionTips":["Pass Double (not Float) values to double columns","Cast numeric types explicitly before serializing","Verify column types after ALTER statements"],"tags":["serialization","cassandra","double","validate"],"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"}