apache/cassandra · error · InvalidRequestException

Invalid list literal for %s of type %s

Error message

Invalid list literal for %s of type %s

What it means

Lists.Value's validateAssignableTo checks that the receiver column's unwrapped type is a ListType. A list literal [..] was supplied for a column/receiver whose type is not a list (set, map, scalar, tuple, etc.), so the literal cannot be assigned.

Source

Thrown at src/java/org/apache/cassandra/cql3/terms/Lists.java:191

                Term t = rt.prepare(keyspace, valueSpec);

                checkFalse(t.containsBindMarker(), "Invalid list literal for %s: bind variables are not supported inside collection literals", receiver.name);

                if (t instanceof Term.NonTerminal)
                    allTerminal = false;

                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));

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use the literal form matching the column type: {..} for sets, {..} for maps, (..) for tuples.
  2. Check the column type via DESCRIBE TABLE or system_schema.columns and align the value.
  3. If the column should be a list, alter the schema or fix the model mapping in the driver/application.

Example fix

// before (tags is set<text>)
INSERT INTO t (id, tags) VALUES (1, ['a','b']);
// after
INSERT INTO t (id, tags) VALUES (1, {'a','b'});
Defensive patterns

Strategy: type-guard

Validate before calling

String colType = /* from system_schema.columns */ "set<text>";
if (!colType.startsWith("list<")) throw new IllegalArgumentException("column is not a list: " + colType);

Type guard

boolean isListLiteralFor(String columnType) { return columnType != null && columnType.startsWith("list<"); }

Prevention

When it happens

Trigger: INSERT/UPDATE with a list literal bound to a non-list column, e.g. INSERT INTO t (id, tags) VALUES (1, ['a']) where tags is a set<text> or text; also during prepared-statement prepare when the raw literal is type-checked.

Common situations: Mixing up set/list/map literal syntax; schema changed the column type after the application code was written; generating SQL where the value shape comes from untyped input.

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/82ec789f2246a50d. Report an issue: GitHub.