{"record":{"id":"82ec789f2246a50d","repo":"apache/cassandra","slug":"invalid-list-literal-for-s-of-type-s","errorCode":null,"errorMessage":"Invalid list literal for %s of type %s","messagePattern":"Invalid list literal for (.+?) of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Lists.java","lineNumber":191,"sourceCode":"                Term t = rt.prepare(keyspace, valueSpec);\n\n                checkFalse(t.containsBindMarker(), \"Invalid list literal for %s: bind variables are not supported inside collection literals\", receiver.name);\n\n                if (t instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(t);\n            }\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue((MultiElementType<?>) receiver.type.unwrap(), values);\n            return allTerminal ? value.bind(FunctionContext.NONE) : value;\n        }\n\n        private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            AbstractType<?> type = receiver.type.unwrap();\n\n            if (!(type instanceof ListType))\n                throw invalidRequest(\"Invalid list literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type());\n\n            ColumnSpecification valueSpec = Lists.valueSpecOf(receiver);\n            for (Term.Raw rt : elements)\n            {\n                if (!rt.testAssignment(keyspace, valueSpec).isAssignable())\n                    throw invalidRequest(\"Invalid list literal for %s: value %s is not of type %s\", receiver.name, rt, valueSpec.type.asCQL3Type());\n            }\n        }\n\n        public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)\n        {\n            return testListAssignment(receiver, elements);\n        }\n\n        @Override\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {\n            return getExactListTypeIfKnown(elements, p -> p.getExactTypeIfKnown(keyspace));","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Lists.java#L173-L209","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the literal form matching the column type: {..} for sets, {..} for maps, (..) for tuples.","Check the column type via DESCRIBE TABLE or system_schema.columns and align the value.","If the column should be a list, alter the schema or fix the model mapping in the driver/application."],"exampleFix":"// before (tags is set<text>)\nINSERT INTO t (id, tags) VALUES (1, ['a','b']);\n// after\nINSERT INTO t (id, tags) VALUES (1, {'a','b'});","handlingStrategy":"type-guard","validationCode":"String colType = /* from system_schema.columns */ \"set<text>\";\nif (!colType.startsWith(\"list<\")) throw new IllegalArgumentException(\"column is not a list: \" + colType);","typeGuard":"boolean isListLiteralFor(String columnType) { return columnType != null && columnType.startsWith(\"list<\"); }","tryCatchPattern":null,"preventionTips":["Bind typed driver collections (List.class codec) instead of building raw literals.","Re-read column types after any schema migration."],"tags":["cql","collections","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}