{"record":{"id":"0ca95e2e2d7825a3","repo":"apache/cassandra","slug":"value-for-a-map-addition-has-to-be-a-map-but-was","errorCode":null,"errorMessage":"Value for a map addition has to be a map, but was: '%s'","messagePattern":"Value for a map addition has to be a map, but was: '(.+?)'","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/Operation.java","lineNumber":368,"sourceCode":"            }\n            else if (!(receiver.type.isMultiCell()))\n                throw new InvalidRequestException(String.format(\"Invalid operation (%s) for frozen collection column %s\", toString(receiver), receiver.name));\n\n            switch (((CollectionType<?>)receiver.type).kind)\n            {\n                case LIST:\n                    return new Lists.Appender(receiver, value.prepare(metadata.keyspace, receiver));\n                case SET:\n                    return new Sets.Adder(receiver, value.prepare(metadata.keyspace, receiver));\n                case MAP:\n                    Term term;\n                    try\n                    {\n                        term = value.prepare(metadata.keyspace, receiver);\n                    }\n                    catch (InvalidRequestException e)\n                    {\n                        throw new InvalidRequestException(String.format(\"Value for a map addition has to be a map, but was: '%s'\", value));\n                    }\n\n                    return new Maps.Putter(receiver, term);\n            }\n            throw new AssertionError();\n        }\n\n        protected String toString(ColumnSpecification column)\n        {\n            return String.format(\"%s = %s + %s\", column.name, column.name, value);\n        }\n\n        public boolean isCompatibleWith(RawUpdate other)\n        {\n            return !(other instanceof SetValue);\n        }\n    }\n","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/Operation.java#L350-L386","documentation":"Cassandra throws this when a map addition operation like `m = m + {...}` is given a value that fails to prepare as a map. The raw term (a literal, bind marker, or expression) could not be parsed/validated against the map type of the target column, so the statement is rejected at prepare (validation) time.","triggerScenarios":"`UPDATE ... SET m = m + ?` or `SET m = m + <literal>` where the bound value or literal is not a valid map (e.g. binding a list/set/JSON value, malformed literal like a bare set, or a bind marker left unset/wrong type).","commonSituations":"Passing a JSON object as a List/ByteBuffer via the driver without mapping it to Map; driver type mismatches between app language and CQL map<_,_>; typo in literal syntax producing a non-map term.","solutions":["Inspect the value being added; ensure it is declared/serialized as the exact map<K,V> type of the column","Use named bound values and confirm the driver-side type matches (e.g. Map<String,Integer> for map<text,int>)","Rewrite a malformed literal into valid map literal syntax: {key: value, ...}","Check for unset/null bind markers supplied where a map value was required"],"exampleFix":"// before\nsession.execute(\"UPDATE t SET m = m + ?\", jsonObjectString);\n// after\nMap<String,Integer> toAdd = Map.of(\"k\", 1);\nsession.execute(\"UPDATE t SET m = m + ?\", toAdd);","handlingStrategy":"validation","validationCode":"if (!(value instanceof Map<?,?> m)) throw new IllegalArgumentException(\"map addition requires a Map, got \" + value.getClass());","typeGuard":"static boolean isMap(Object v){ return v instanceof Map; }","tryCatchPattern":"try { session.execute(ps.bind(mapValue)); } catch (InvalidQueryException e) { if (e.getMessage().contains(\"has to be a map\")) { /* fix bind type */ } else throw e; }","preventionTips":["Bind typed Map<K,V> objects matching the column definition","Validate literal syntax for map additions before executing","Keep driver codec types aligned with schema types"],"tags":["cql","type-mismatch","collections","prepared-statement"],"backgroundTag":"invalid-argument-value","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"}