apache/cassandra · error · InvalidRequestException
Invalid list literal for %s: value %s is not of type %s
Error message
Invalid list literal for %s: value %s is not of type %s
What it means
When the receiver is a list, validateAssignableTo type-checks every element literal against the list's value type (Lists.valueSpecOf). If any element fails testAssignment, this error reports which element and what type was expected.
Source
Thrown at src/java/org/apache/cassandra/cql3/terms/Lists.java:197
values.add(t);
}
MultiElements.DelayedValue value = new MultiElements.DelayedValue((MultiElementType<?>) receiver.type.unwrap(), values);
return allTerminal ? value.bind(FunctionContext.NONE) : value;
}
private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException
{
AbstractType<?> type = receiver.type.unwrap();
if (!(type instanceof ListType))
throw invalidRequest("Invalid list literal for %s of type %s", receiver.name, receiver.type.asCQL3Type());
ColumnSpecification valueSpec = Lists.valueSpecOf(receiver);
for (Term.Raw rt : elements)
{
if (!rt.testAssignment(keyspace, valueSpec).isAssignable())
throw invalidRequest("Invalid list literal for %s: value %s is not of type %s", receiver.name, rt, valueSpec.type.asCQL3Type());
}
}
public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)
{
return testListAssignment(receiver, elements);
}
@Override
public AbstractType<?> getExactTypeIfKnown(String keyspace)
{
return getExactListTypeIfKnown(elements, p -> p.getExactTypeIfKnown(keyspace));
}
@Override
public AbstractType<?> getCompatibleTypeIfKnown(String keyspace)
{
return Lists.getPreferredCompatibleType(elements, p -> p.getCompatibleTypeIfKnown(keyspace));View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Make every element match the list's declared value type (cast or convert offending elements).
- Check the element type with DESCRIBE TABLE and fix the data source generating the literal.
- For mixed input, preprocess in the application and bind typed parameters instead of raw literals.
Example fix
// before (nums is list<text>) INSERT INTO t (id, nums) VALUES (1, [1, 2]); // after INSERT INTO t (id, nums) VALUES (1, ['1', '2']);
Defensive patterns
Strategy: validation
Validate before calling
// parse declared element type, e.g. list<text> -> text, then coerce each element before building the literal elements.forEach(e -> coerceToType(e, elementType));
Prevention
- Validate element types at the data source (JSON/CSV import) boundary.
- Prefer prepared statements with typed binding over string-built literals.
When it happens
Trigger: INSERT/UPDATE with a list literal containing an element of the wrong type, e.g. [1, 'two'] for list<text>, or [user-defined-literal] not assignable to a UDT element type.
Common situations: Mixed-type literals generated programmatically; untyped JSON/CSV import mapped directly to CQL literals; schema element type changed (e.g. int -> text) while client literals did not.
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
- Value for a map addition has to be a map, but was: '%s'
- Value for a map substraction has to be a set, but was: '%s'
- Invalid operation (%s) for non list column %s
- Unexpected receiver type '%s'; only list and vector are expe
- Invalid list literal for %s of type %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/847e1932110f3192.
Report an issue: GitHub.