apache/cassandra · error · IllegalArgumentException

%s

Error message

%s

What it means

In the same parseStatement method, when the CQL string cannot be parsed at all (ANTLR RecognitionException) or fails semantic validation (RequestValidationException, e.g. unknown table/column, bad syntax), the method rethrows it as an IllegalArgumentException whose message is the underlying parser/validator message. The '%s' in the catalog is the dynamic parser message; it tells the developer exactly what part of the CQL was invalid.

Source

Thrown at tools/stress/src/org/apache/cassandra/io/sstable/StressCQLSSTableWriter.java:723

            return insert;
        }
    }

    public static <T extends CQLStatement.Raw> T parseStatement(String query, Class<T> klass, String type)
    {
        try
        {
            CQLStatement.Raw stmt = CQLFragmentParser.parseAnyUnhandled(CqlParser::query, query);

            if (!stmt.getClass().equals(klass))
                throw new IllegalArgumentException("Invalid query, must be a " + type + " statement but was: " + stmt.getClass());

            return klass.cast(stmt);
        }
        catch (RecognitionException | RequestValidationException e)
        {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Read the wrapped message for the exact syntax or validation problem and fix the CQL string.
  2. Validate the CQL in cqlsh or a CQL editor before embedding it in the stress tool.
  3. Ensure the keyspace and table exist and are spelled correctly (case-sensitive quoted identifiers).
  4. Catch IllegalArgumentException around writer construction and log e.getCause() (the original RequestValidationException) for full details.

Example fix

// before
String cql = "INSERT INTO ks.t (k, v) VALUES (?, ?"; // missing ')'
// after
String cql = "INSERT INTO ks.t (k, v) VALUES (?, ?)";
Defensive patterns

Strategy: validation

Validate before calling

if (cql == null || cql.trim().isEmpty())
    throw new IllegalArgumentException("CQL string must be non-empty");
// optionally pre-validate with a parser or cqlsh dry-run

Try / catch

try {
    writer = StressCQLSSTableWriter.builder(schema, cql).build();
} catch (IllegalArgumentException e) {
    Throwable cause = e.getCause();
    if (cause instanceof RequestValidationException)
        throw new IllegalStateException("Invalid CQL: " + cause.getMessage(), cause);
    throw e;
}

Prevention

When it happens

Trigger: Passing a syntactically invalid CQL string (bad syntax, missing parentheses, wrong placeholders) or a semantically invalid one (unknown keyspace/table/column, invalid type usage) to StressCQLSSTableWriter.parseStatement, causing CQLFragmentParser.parseAnyUnhandled to throw RecognitionException or RequestValidationException.

Common situations: Typo in table or column names; forgetting to add the keyspace or using one that does not exist; CQL that is valid interactively but invalid here (e.g. empty string); copy-pasted CQL containing cqlsh-only directives.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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