{"record":{"id":"f55a30db200e23fa","repo":"apache/cassandra","slug":"invalid-map-literal-for-s-value-s-is-not-of-typ","errorCode":null,"errorMessage":"Invalid map literal for %s: value %s is not of type %s","messagePattern":"Invalid map literal for (.+?): value (.+?) is not of type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/Maps.java","lineNumber":221,"sourceCode":"            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\n            ColumnSpecification keySpec = Maps.keySpecOf(receiver);\n            ColumnSpecification valueSpec = Maps.valueSpecOf(receiver);\n            for (Pair<Term.Raw, Term.Raw> entry : entries)\n            {\n                if (!entry.left.testAssignment(keyspace, keySpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: key %s is not of type %s\", receiver.name, entry.left, keySpec.type.asCQL3Type()));\n                if (!entry.right.testAssignment(keyspace, valueSpec).isAssignable())\n                    throw new InvalidRequestException(String.format(\"Invalid map literal for %s: value %s is not of type %s\", receiver.name, entry.right, valueSpec.type.asCQL3Type()));\n            }\n        }\n\n        public AssignmentTestable.TestResult testAssignment(String keyspace, ColumnSpecification receiver)\n        {\n            return testMapAssignment(receiver, entries);\n        }\n\n        @Override\n        public AbstractType<?> getExactTypeIfKnown(String keyspace)\n        {\n            return getExactMapTypeIfKnown(entries, p -> p.getExactTypeIfKnown(keyspace));\n        }\n\n        @Override\n        public AbstractType<?> getCompatibleTypeIfKnown(String keyspace)\n        {\n            return Maps.getPreferredCompatibleType(entries, p -> p.getCompatibleTypeIfKnown(keyspace));","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/Maps.java#L203-L239","documentation":"Fired by Maps literal preparation when a map literal value element's type is not assignable to the declared value type of the target map column. It is a statement-preparation validation guard reached after key validation; the offending value expression fails type assignability against MapType.getValueType().","triggerScenarios":"Preparing e.g. `SET m = {'k': 'not-an-int'}` where the value type is int (map<text,int>), or nested collection values of the wrong type.","commonSituations":"Sending string values for numeric/timestamp value types; schema migration changed the value type; templated queries injecting wrong literal forms.","solutions":["Make literal values match the declared value type (e.g. `{'k': 42}` for map<text,int>).","Check the value type in system_schema.columns and align the query.","Bind the whole map as a typed parameter so the driver performs type conversion."],"exampleFix":"// before (map<text,int>)\n\"UPDATE t SET m = {'k':'42'} WHERE k=?\"\n// after\n\"UPDATE t SET m = {'k':42} WHERE k=?\"","handlingStrategy":"validation","validationCode":"// values must be literals assignable to the map value type, e.g. map<?,int>\nObject v = entry.getValue();\nif (!(v instanceof Integer)) throw new IllegalArgumentException(\"value must be int, got \" + v.getClass());","typeGuard":null,"tryCatchPattern":"try { session.prepare(sql); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"value\") && e.getMessage().contains(\"is not of type\")) { /* fix literal value types */ } else throw e; }","preventionTips":["Match literal forms to declared value types (no quotes for numbers)","Bind whole maps with typed codecs instead of string literals","Run query validation against a test schema in CI"],"tags":["cql","map","type-mismatch","validation"],"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"}