apache/cassandra · error · IllegalStateException

Unrecognized kind {kind}

Error message

Unrecognized kind {kind}

What it means

Returns the serializer for a TxnDataValue.Kind: key → TxnDataKeyValue.serializer, range → TxnDataRangeValue.serializer. Unlike sibling switches that throw IllegalArgumentException, this throws IllegalStateException because the default case is considered unreachable for a well-formed two-value enum — hitting it signals internal state corruption or a build mismatch.

Source

Thrown at src/java/org/apache/cassandra/service/accord/txn/TxnDataValue.java:64

        int id;

        Kind(int id)
        {
            this.id = id;
        }

        @SuppressWarnings("unchecked")
        public <T extends TxnDataValue> IVersionedSerializer<T> serializer()
        {
            switch (this)
            {
                case key:
                    return (IVersionedSerializer<T>) TxnDataKeyValue.serializer;
                case range:
                    return (IVersionedSerializer<T>) TxnDataRangeValue.serializer;
                default:
                    throw new IllegalStateException("Unrecognized kind " + this);
            }
        }
    }

    TxnDataValue.Kind kind();

    TxnDataValue merge(TxnDataValue other);
    @Nullable TxnDataValue without(Ranges ranges);
    long maxTimestamp();

    long estimatedSizeOnHeap();

    IVersionedSerializer<TxnDataValue> serializer = new IVersionedSerializer<>()
    {
        @SuppressWarnings("unchecked")
        @Override
        public void serialize(TxnDataValue txnDataValue, DataOutputPlus out, Version version) throws IOException
        {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Ensure a single consistent Cassandra build is deployed (check for duplicate/stale JARs on the classpath).
  2. Rebuild and redeploy if the enum was modified locally.
  3. If adding a new Kind, extend the switch with the corresponding serializer before using it.
Defensive patterns

Strategy: try-catch

Validate before calling

TxnDataValue.Kind k = ...;
if (k != TxnDataValue.Kind.key && k != TxnDataValue.Kind.range)
    throw new IllegalStateException("Unexpected TxnDataValue kind: " + k);

Type guard

static boolean isKnownKind(TxnDataValue.Kind k) {
    return k == TxnDataValue.Kind.key || k == TxnDataValue.Kind.range;
}

Try / catch

try {
    IVersionedSerializer<T> s = kind.serializer();
} catch (IllegalStateException e) {
    logger.error("Corrupted/unknown TxnDataValue kind - classpath or build mismatch", e);
    throw new IllegalStateException("Aborting: serializer unavailable", e);
}

Prevention

When it happens

Trigger: Calling Kind.serializer() with a Kind value that is neither 'key' nor 'range' — only possible via a mismatched enum (different class versions on the classpath) or corrupted in-memory state.

Common situations: Stale JARs / mixed Cassandra versions in the classpath; shaded or duplicate TxnDataValue classes; memory corruption or bytecode weaving tools altering the enum.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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