{"record":{"id":"847e1932110f3192","repo":"apache/cassandra","slug":"invalid-list-literal-for-s-value-s-is-not-of-ty","errorCode":null,"errorMessage":"Invalid list literal for %s: value %s is not of type %s","messagePattern":"Invalid list literal for (.+?): value (.+?) is not of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Lists.java","lineNumber":197,"sourceCode":"\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));\n        }\n\n        @Override\n        public AbstractType<?> getCompatibleTypeIfKnown(String keyspace)\n        {\n            return Lists.getPreferredCompatibleType(elements, p -> p.getCompatibleTypeIfKnown(keyspace));","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Lists.java#L179-L215","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (nums is list<text>)\nINSERT INTO t (id, nums) VALUES (1, [1, 2]);\n// after\nINSERT INTO t (id, nums) VALUES (1, ['1', '2']);","handlingStrategy":"validation","validationCode":"// parse declared element type, e.g. list<text> -> text, then coerce each element before building the literal\nelements.forEach(e -> coerceToType(e, elementType));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate element types at the data source (JSON/CSV import) boundary.","Prefer prepared statements with typed binding over string-built literals."],"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"}