{"record":{"id":"3e1811dc17e2c012","repo":"apache/cassandra","slug":"emptytype-only-accept-empty-values","errorCode":null,"errorMessage":"EmptyType only accept empty values","messagePattern":"EmptyType only accept empty values","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/EmptySerializer.java","lineNumber":44,"sourceCode":"public class EmptySerializer extends TypeSerializer<Void>\n{\n    public static final EmptySerializer instance = new EmptySerializer();\n\n    public <V> Void deserialize(V value, ValueAccessor<V> accessor)\n    {\n        validate(value, accessor);\n        return null;\n    }\n\n    public ByteBuffer serialize(Void value)\n    {\n        return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (!accessor.isEmpty(value))\n            throw new MarshalException(\"EmptyType only accept empty values\");\n    }\n\n    public String toString(Void value)\n    {\n        return \"\";\n    }\n\n    public Class<Void> getType()\n    {\n        return Void.class;\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":57,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/EmptySerializer.java#L26-L57","documentation":"EmptyType is a special Cassandra comparator that can only store zero-length byte values. The serializer's validate() rejects any non-empty byte buffer, because EmptyType has no meaningful representation for actual data. It is typically used as a dummy key type where the value carries no information.","triggerScenarios":"Calling EmptyType.validate(value, accessor) (directly or via deserialize/validation paths such as compare or asCQLType) with a byte buffer whose size is greater than 0.","commonSituations":"Declaring a column or clustering key as EmptyType and then INSERTing a non-null literal (e.g. int or text) instead of leaving it empty/null; a driver or migration writing real bytes into an EmptyType column; accidental use of EmptyType instead of the intended type in a table schema.","solutions":["Write only empty values (0 bytes) to columns typed EmptyType; use an explicit empty marker per your CQL version (e.g. 0x blob literal) or leave the column unset.","Check the table schema (DESCRIBE / system_schema) and change the column to the intended type (int, text, blob) if EmptyType was chosen by mistake.","If used as a dummy partition-key component to keep rows in one partition, ensure the application serializes nothing for that component."],"exampleFix":"// before\nsession.execute(\"INSERT INTO t (pk, empty_col) VALUES (1, 42)\");\n// after\nsession.execute(\"INSERT INTO t (pk, empty_col) VALUES (1, 0x)\"); // or omit empty_col entirely","handlingStrategy":"validation","validationCode":"if (value != null && value.remaining() > 0) throw new IllegalArgumentException(\"EmptyType columns accept only 0-byte values\");","typeGuard":"boolean isEmptyTypeValue(java.nio.ByteBuffer b) { return b == null || b.remaining() == 0; }","tryCatchPattern":null,"preventionTips":["Never bind literals into EmptyType columns; leave them unset or write an explicit empty value","Verify the column type in system_schema before writing when reusing write code across tables"],"tags":["cassandra","serialization","type-validation","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}