{"record":{"id":"e4de2f10e39ec37c","repo":"apache/cassandra","slug":"expected-1-or-0-byte-value-d","errorCode":null,"errorMessage":"Expected 1 or 0 byte value (%d)","messagePattern":"Expected 1 or 0 byte value \\((.+?)\\)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/BooleanSerializer.java","lineNumber":49,"sourceCode":"\n    public <V> Boolean deserialize(V value, ValueAccessor<V> accessor)\n    {\n        if (value == null || accessor.isEmpty(value))\n            return null;\n\n        return accessor.getByte(value, 0) != 0;\n    }\n\n    public ByteBuffer serialize(Boolean value)\n    {\n        return (value == null) ? ByteBufferUtil.EMPTY_BYTE_BUFFER\n                               : value ? TRUE : FALSE; // false\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (accessor.size(value) > 1)\n            throw new MarshalException(String.format(\"Expected 1 or 0 byte value (%d)\", accessor.size(value)));\n    }\n\n    public String toString(Boolean value)\n    {\n        return value == null ? \"\" : value.toString();\n    }\n\n    public Class<Boolean> getType()\n    {\n        return Boolean.class;\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/BooleanSerializer.java#L31-L62","documentation":"BooleanSerializer.validate rejects any serialized boolean whose byte length is not 0 or 1; a boolean column must be a single byte (or empty for null). MarshalException(\"Expected 1 or 0 byte value (%d)\") indicates the buffer written to a boolean column has the wrong length.","triggerScenarios":"Writing an integer, string (\"true\"), or multi-byte value into a boolean column via a driver or tool that does not encode booleans as 1 byte; deserializing an SSTable cell typed boolean that was written with a different type (src/java/org/apache/cassandra/serializers/BooleanSerializer.java:49).","commonSituations":"INSERT with a string literal 'true' into boolean via a non-typing tool (cqlsh usually coerces, external loaders may not); sstableloader with mismatched schema; custom clients serializing Java Boolean.toString instead of the 1-byte wire format.","solutions":["Send the value as a boolean type through the driver (1-byte encoding), not as text or int.","If loading from external data, convert 'true'/'false' strings to real booleans before writing.","Fix the schema if the column actually stores multi-byte values: alter the column to the correct type.","For corrupt stored data, rewrite the partition with correctly typed values."],"exampleFix":"// before\nstmt.setString(\"v\", \"true\"); // 4 bytes -> MarshalException on boolean column\n// after\nstmt.setBool(\"v\", true); // encodes as single 0x01 byte","handlingStrategy":"type-guard","validationCode":"if (v != null && v.size() > 1) throw new IllegalArgumentException(\"boolean must be empty or 1 byte\");","typeGuard":"static boolean isValidBooleanValue(ByteBuffer v) { return v == null || v.remaining() <= 1; }","tryCatchPattern":"try { writeBoolean(stmt, flag); } catch (InvalidQueryException e) { /* value not encoded as 1-byte boolean */ }","preventionTips":["Use setBool/setBoolean driver methods, never setString for booleans","Convert 'true'/'false' strings during ETL before load","Keep loader schema identical to target schema","Round-trip test one row before bulk loading"],"tags":["serialization","boolean","type-mismatch","validation"],"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"}