{"record":{"id":"559a886ec31788af","repo":"apache/cassandra","slug":"expected-an-empty-string-but-got-s","errorCode":null,"errorMessage":"Expected an empty string, but got: %s","messagePattern":"Expected an empty string, but got: (.+?)","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/EmptyType.java","lineNumber":110,"sourceCode":"\n    public <V> String getString(V value, ValueAccessor<V> accessor)\n    {\n        return \"\";\n    }\n\n    public ByteBuffer fromString(String source) throws MarshalException\n    {\n        if (!source.isEmpty())\n            throw new MarshalException(String.format(\"'%s' is not empty\", source));\n\n        return ByteBufferUtil.EMPTY_BYTE_BUFFER;\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (!(parsed instanceof String))\n            throw new MarshalException(String.format(\"Expected an empty string, but got: %s\", parsed));\n        if (!((String) parsed).isEmpty())\n            throw new MarshalException(String.format(\"'%s' is not empty\", parsed));\n\n        return new Constants.Value(ByteBufferUtil.EMPTY_BYTE_BUFFER);\n    }\n\n    @Override\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.EMPTY;\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return \"\\\"\\\"\";\n    }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/EmptyType.java#L92-L128","documentation":"EmptyType.fromJSONObject() requires the parsed JSON value to be a String (and then an empty one). If the JSON value is not a string at all (number, boolean, object, null), this MarshalException is thrown reporting the value received. This enforces that JSON input for 'empty'-typed fields is at least string-typed before the emptiness check applies.","triggerScenarios":"INSERT JSON / fromJSONObject on an empty-type column with {\"col\": 0}, {\"col\": null}, or {\"col\": {}} instead of {\"col\": \"\"}.","commonSituations":"Clients serialize nulls or zeros for empty columns; schema uses 'empty' as a placeholder but the app still writes payload data; generic JSON pipeline doesn't special-case EmptyType.","solutions":["Send the JSON string \"\" for empty-typed columns","Drop the field or set it to null via non-JSON paths if the intent is 'no value'","Change the column type if actual data must be stored"],"exampleFix":"// before\n{\"placeholder\": null}\n// after\n{\"placeholder\": \"\"}","handlingStrategy":"type-guard","validationCode":"if (!(jsonValue instanceof String)) throw new IllegalArgumentException(\"EmptyType JSON field must be the string \\\"\\\"\");","typeGuard":null,"tryCatchPattern":"try { EmptyType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* coerce or reject payload */ }","preventionTips":["Coerce nulls to \"\" for empty-typed columns in the JSON pipeline","Validate JSON field types against column types before INSERT JSON","Avoid reusing a formerly-typed column as 'empty' without cleaning payloads"],"tags":["cassandra","json","type-mismatch"],"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"}