{"record":{"id":"f2a1a2650db05f42","repo":"apache/cassandra","slug":"value-s-is-not-a-valid-representation-of-a-vari","errorCode":null,"errorMessage":"Value '%s' is not a valid representation of a varint value","messagePattern":"Value '(.+?)' is not a valid representation of a varint value","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/IntegerType.java","lineNumber":482,"sourceCode":"        }\n        catch (Exception e)\n        {\n            throw new MarshalException(String.format(\"unable to make int from '%s'\", source), e);\n        }\n\n        return decompose(integerType);\n    }\n\n    @Override\n    public Term fromJSONObject(Object parsed) throws MarshalException\n    {\n        try\n        {\n            return new Constants.Value(getSerializer().serialize(new BigInteger(parsed.toString())));\n        }\n        catch (NumberFormatException exc)\n        {\n            throw new MarshalException(String.format(\n                    \"Value '%s' is not a valid representation of a varint value\", parsed));\n        }\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 boolean isValueCompatibleWithInternal(AbstractType<?> otherType)\n    {\n        return this == otherType || Int32Type.instance.isValueCompatibleWith(otherType) || LongType.instance.isValueCompatibleWith(otherType);\n    }\n\n    public CQL3Type asCQL3Type()\n    {","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/IntegerType.java#L464-L500","documentation":"IntegerType.fromJSONObject() converts the parsed JSON value to a varint by doing new BigInteger(parsed.toString()); if that string is not a valid integer literal, NumberFormatException is caught and rethrown as this MarshalException. The input here may be a non-String JSON value (numbers, booleans, objects) whose toString() is not a valid BigInteger literal.","triggerScenarios":"Calling IntegerType.instance.fromJSONObject(parsed, protocolVersion) where parsed.toString() is not a valid integer literal, e.g. parsed = 3.14 (Double -> \"3.14\") or parsed = true (\"true\"); the BigInteger constructor throws NumberFormatException.","commonSituations":"JSON payloads with floats destined for varint columns; boolean/nested-object values in varint fields; double-encoded JSON strings producing quoted literals like \"\\\"123\\\"\".","solutions":["Send the varint value as an integral JSON number or integer string","Use the decimal type for fractional values instead of varint","Validate that the value's toString() matches ^[+-]?\\d+$ before calling fromJSONObject","Catch MarshalException and report the offending value"],"exampleFix":"// before\n{\"v\": 3.14} // varint column\n// after\n{\"v\": 3}  // or change column to decimal for 3.14","handlingStrategy":"validation","validationCode":"if (!parsed.toString().matches(\"[+-]?\\\\d+\"))\n    throw new IllegalArgumentException(\"Not a valid varint representation: \" + parsed);","typeGuard":"static boolean isValidVarintJson(Object v) { return (v instanceof Number && !(v instanceof Double && ((Double) v != Math.floor((Double) v)))) || (v instanceof String && ((String) v).matches(\"[+-]?\\\\d+\")); }","tryCatchPattern":"try { IntegerType.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* parsed.toString() not an integer literal; reject */ }","preventionTips":["Send varint values as integral JSON numbers or digit-only strings","Use decimal type for fractional values","Disable double-encoding of JSON strings in producers","Validate varint literals before calling fromJSONObject"],"tags":["cassandra","marshalling","json","varint"],"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-14T21:17:11.552Z"}