apache/cassandra · error · MarshalException

Expected an empty string, but got: %s

Error message

Expected an empty string, but got: %s

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/EmptyType.java:110

    public <V> String getString(V value, ValueAccessor<V> accessor)
    {
        return "";
    }

    public ByteBuffer fromString(String source) throws MarshalException
    {
        if (!source.isEmpty())
            throw new MarshalException(String.format("'%s' is not empty", source));

        return ByteBufferUtil.EMPTY_BYTE_BUFFER;
    }

    @Override
    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        if (!(parsed instanceof String))
            throw new MarshalException(String.format("Expected an empty string, but got: %s", parsed));
        if (!((String) parsed).isEmpty())
            throw new MarshalException(String.format("'%s' is not empty", parsed));

        return new Constants.Value(ByteBufferUtil.EMPTY_BYTE_BUFFER);
    }

    @Override
    public CQL3Type asCQL3Type()
    {
        return CQL3Type.Native.EMPTY;
    }

    @Override
    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
    {
        return "\"\"";
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Send the JSON string "" for empty-typed columns
  2. Drop the field or set it to null via non-JSON paths if the intent is 'no value'
  3. Change the column type if actual data must be stored

Example fix

// before
{"placeholder": null}
// after
{"placeholder": ""}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(jsonValue instanceof String)) throw new IllegalArgumentException("EmptyType JSON field must be the string \"\"");

Try / catch

try { EmptyType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* coerce or reject payload */ }

Prevention

When it happens

Trigger: INSERT JSON / fromJSONObject on an empty-type column with {"col": 0}, {"col": null}, or {"col": {}} instead of {"col": ""}.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/559a886ec31788af. Report an issue: GitHub.