apache/cassandra · error · NonEmptyWriteException

Dropping data... (Attempted to write a non-empty value…

Error message

Dropping data... (Attempted to write a non-empty value using EmptyType)

What it means

EmptyType columns must always serialize as zero bytes. When a non-empty value is written, writeValue consults the serialization.empty_type_nonempty_writes policy: FAIL (default) throws AssertionError, LOG_DATA_LOSS logs 'Dropping data...' with a NonEmptyWriteException stack and drops, SILENT_DATA_LOSS silently drops. This protects against silent data loss from schema mistakes (CASSANDRA-15790).

Solutions

  1. Fix the application/driver to write only empty (zero-length) values for empty-typed columns
  2. If the column should hold data, ALTER the schema to a real type and migrate data
  3. Leave the default property (FAIL) so such writes fail loudly instead of dropping data
  4. If LOG_DATA_LOSS was intentionally set, audit logs for NonEmptyWriteException to find offending writes

Example fix

// before: inserting a value into an empty column
INSERT INTO t (k, flag) VALUES (1, 'yes');
// after: empty columns accept only empty values
INSERT INTO t (k, flag) VALUES (1, '');
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side guard: only send empty values to empty-typed columns
if (colType.equals("empty") && value != null && value.length() > 0)
    throw new IllegalArgumentException("Non-empty value for empty column: " + colName);

Try / catch

try { session.execute(insert); } catch (AssertionError | DriverException e) { logger.error("Write to empty-typed column rejected: {}", e.getMessage()); }

Prevention

When it happens

Trigger: INSERT/UPDATE with a non-empty value (e.g. a string or int) into a column of type empty, or a driver/application serializing a value into an empty-typed column, with the behavior property set to LOG_DATA_LOSS.

Common situations: Applications writing real values to a column intended as an 'exists-only' placeholder; schema migration accidentally changed a column to empty type; misuse of empty columns intended for existence checks.

Related errors


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

Appendix: source

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

    public ByteBuffer readBuffer(DataInputPlus in, int maxValueSize)
    {
        return ByteBufferUtil.EMPTY_BYTE_BUFFER;
    }

    @Override
    public void writeValue(ByteBuffer value, DataOutputPlus out)
    {
        if (!value.hasRemaining())
            return;
        // In 3.0 writeValue was added which required EmptyType to write data, and relied on caller to never do that;
        // that behavior was unsafe so guard against it.  There are configurable behaviors, but the only allowed cases
        // should be *_DATA_LOSS (last resort... really should avoid this) and fail; fail should be preferred in nearly
        // all cases.
        // see CASSANDRA-15790
        switch (NON_EMPTY_WRITE_BEHAVIOR)
        {
            case LOG_DATA_LOSS:
                NON_EMPTY_WRITE_LOGGER.warn("Dropping data...", new NonEmptyWriteException("Attempted to write a non-empty value using EmptyType"));
            case SILENT_DATA_LOSS:
                return;
            case FAIL:
            default:
                throw new AssertionError("Attempted to write a non-empty value using EmptyType");
        }
    }

    private static final class NonEmptyWriteException extends RuntimeException
    {
        NonEmptyWriteException(String message)
        {
            super(message);
        }
    }

    @Override
    public ByteBuffer getMaskedValue()

View on GitHub (pinned to 88fd0f6a0e)