{"record":{"id":"8fc6e98e04ab450d","repo":"apache/cassandra","slug":"invalid-map-literal-for-s-bind-variables-are-not","errorCode":null,"errorMessage":"Invalid map literal for %s: bind variables are not supported inside collection literals","messagePattern":"Invalid map literal for (.+?): bind variables are not supported inside collection literals","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Maps.java","lineNumber":195,"sourceCode":"\n        public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            validateAssignableTo(keyspace, receiver);\n\n            ColumnSpecification keySpec = Maps.keySpecOf(receiver);\n            ColumnSpecification valueSpec = Maps.valueSpecOf(receiver);\n            // In CQL maps are represented as a list of key value pairs (e.g. {k1 : v1, k2 : v2, ...}).\n            // Whereas, internally maps are serialized as a lists where each key is followed by its value (e.g. [k1, v1, k2, v2, ...])\n            // Therefore, we must go from one format to another.\n            List<Term> values = new ArrayList<>(entries.size() << 1);\n            boolean allTerminal = true;\n            for (Pair<Term.Raw, Term.Raw> entry : entries)\n            {\n                Term k = entry.left.prepare(keyspace, keySpec);\n                Term v = entry.right.prepare(keyspace, valueSpec);\n\n                if (k.containsBindMarker() || v.containsBindMarker())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: bind variables are not supported inside collection literals\", receiver.name));\n\n                if (k instanceof Term.NonTerminal || v instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(k);\n                values.add(v);\n            }\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue((MultiElementType<?>) receiver.type.unwrap(), values);\n            return allTerminal ? value.bind(QueryOptions.DEFAULT) : 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 MapType))\n                throw new InvalidRequestException(String.format(\"Invalid map literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type()));\n","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Maps.java#L177-L213","documentation":"Cassandra map literals (e.g. `SET m = {'a': 1}`) cannot contain bind markers inside them; the whole literal must either be a literal or bound as a single value. During prepare, if any key or term of the map literal contains a bind marker, preparation fails.","triggerScenarios":"Preparing a statement like `INSERT ... SET m = {? : ?}` or `UPDATE ... SET m['?'] = ?` where a bind marker appears inside a map literal's entries.","commonSituations":"Developers assuming named parameters work anywhere in a statement; query builders interpolating bind markers into collection literals; migrating code from concatenation to parameterized queries.","solutions":["Bind the entire map as one parameter: `SET m = ?` and pass a Map value.","Use literals directly in the map: `SET m = {'key': 'value'}`.","For a single key update use positional key binding on the accessor form `m[?] = ?`, not inside a literal."],"exampleFix":"// before\n\"UPDATE t SET m = {? : ?} WHERE k=?\"\n// after\n\"UPDATE t SET m[?] = ? WHERE k=?\"  // or bind whole map: SET m = ?","handlingStrategy":"validation","validationCode":"if (query.matches(\".*\\{[^}]*\\?.*\\}.*\")) throw new IllegalArgumentException(\"bind markers not allowed inside map literals\");","typeGuard":null,"tryCatchPattern":"try { session.prepare(sql); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"bind variables are not supported inside collection literals\")) { /* rewrite query */ } else throw e; }","preventionTips":["Bind whole collections as single parameters (SET m = ?)","Use m[?] = ? form for per-key updates","Review query templates for ? inside {} or [] literals"],"tags":["cql","bind-marker","map","prepare"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}