{"record":{"id":"c41e1a3f27053260","repo":"apache/cassandra","slug":"expected-a-short-value-but-got-a-s-s","errorCode":null,"errorMessage":"Expected a short value, but got a %s: %s","messagePattern":"Expected a short value, but got a (.+?): (.+?)","errorType":"exception","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/ShortType.java","lineNumber":95,"sourceCode":"\n        try\n        {\n            s = Short.parseShort(source);\n        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"Unable to make short from '%s'\", source), e);\n        }\n\n        return decompose(s);\n    }\n\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        if (parsed instanceof String || parsed instanceof Number)\n            return new Constants.Value(fromString(String.valueOf(parsed)));\n\n        throw new MarshalException(String.format(\n                \"Expected a short value, but got a %s: %s\", parsed.getClass().getSimpleName(), parsed));\n    }\n\n    @Override\n    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)\n    {\n        return Objects.toString(getSerializer().deserialize(buffer), \"\\\"\\\"\");\n    }\n\n    @Override\n    public CQL3Type asCQL3Type()\n    {\n        return CQL3Type.Native.SMALLINT;\n    }\n\n    public TypeSerializer<Short> getSerializer()\n    {\n        return ShortSerializer.instance;","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/ShortType.java#L77-L113","documentation":"ShortType.fromJSONObject converts a parsed JSON value into a short Term. Only JSON strings and numbers are accepted; any other JSON type (object, array, boolean, null) cannot be interpreted as a short and triggers this MarshalException naming the offending Java class.","triggerScenarios":"Executing a JSON insert (INSERT ... JSON or fromJson()) where a smallint column receives a JSON true/false/null/array/object instead of a number or numeric string.","commonSituations":"JSON payloads generated programmatically where a field is accidentally a nested object or null because the upstream value was missing; schema drift between the client model and the CQL table.","solutions":["Send the smallint as a JSON number or numeric string (e.g. 42 or \"42\").","Guard the JSON document before sending: check the field is a number/string and non-null.","Fix the producer so absent values are omitted rather than serialized as null/objects."],"exampleFix":"// before\n{\"id\": 1, \"smallint_col\": null}\n// after\n{\"id\": 1, \"smallint_col\": 42}","handlingStrategy":"type-guard","validationCode":"if (v != null && !(v instanceof String) && !(v instanceof Number)) throw new IllegalArgumentException(\"smallint must be number/string\");","typeGuard":"boolean isShortLike(Object v) { return v instanceof String || v instanceof Number; }","tryCatchPattern":"try { return ShortType.instance.fromJSONObject(parsed); } catch (MarshalException e) { /* handle non-numeric JSON type */ }","preventionTips":["Validate JSON payloads against a schema before INSERT JSON","Ensure producers omit missing fields instead of emitting null/objects","Map client numeric types to JSON numbers, not nested wrappers"],"tags":["cassandra","json","type-mismatch","marshal"],"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"}