apache/cassandra · error · MarshalException
Value '%s' is not a valid representation of a varint value
Error message
Value '%s' is not a valid representation of a varint value
What it means
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.
Source
Thrown at src/java/org/apache/cassandra/db/marshal/IntegerType.java:482
}
catch (Exception e)
{
throw new MarshalException(String.format("unable to make int from '%s'", source), e);
}
return decompose(integerType);
}
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
try
{
return new Constants.Value(getSerializer().serialize(new BigInteger(parsed.toString())));
}
catch (NumberFormatException exc)
{
throw new MarshalException(String.format(
"Value '%s' is not a valid representation of a varint value", parsed));
}
}
@Override
public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
{
return Objects.toString(getSerializer().deserialize(buffer), "\"\"");
}
@Override
public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
{
return this == otherType || Int32Type.instance.isValueCompatibleWith(otherType) || LongType.instance.isValueCompatibleWith(otherType);
}
public CQL3Type asCQL3Type()
{View on GitHub (pinned to 88fd0f6a0e)
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
Example fix
// before
{"v": 3.14} // varint column
// after
{"v": 3} // or change column to decimal for 3.14 Defensive patterns
Strategy: validation
Validate before calling
if (!parsed.toString().matches("[+-]?\\d+"))
throw new IllegalArgumentException("Not a valid varint representation: " + parsed); Type guard
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+")); } Try / catch
try { IntegerType.instance.fromJSONObject(parsed, pv); } catch (MarshalException e) { /* parsed.toString() not an integer literal; reject */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: JSON payloads with floats destined for varint columns; boolean/nested-object values in varint fields; double-encoded JSON strings producing quoted literals like "\"123\"".
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Expected a float value, but got a %s: %s
- Expected a string representation of an inet value, but got a
- Expected an int value, but got a %s: %s
- unable to make int from '%s'
- Expected a UTF-8 string, but got a %s: %s
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/f2a1a2650db05f42.
Report an issue: GitHub.