apache/cassandra · error · MarshalException

unable to make int from '%s'

Error message

unable to make int from '%s'

What it means

IntegerType (varint) fromString() constructs a BigInteger from the source text with new BigInteger(source); any parse failure is wrapped in this MarshalException. The string must be a valid arbitrary-precision integer literal (optional sign followed by digits).

Source

Thrown at src/java/org/apache/cassandra/db/marshal/IntegerType.java:467

        return buf;
    }

    public ByteBuffer fromString(String source) throws MarshalException
    {
        // Return an empty ByteBuffer for an empty string.
        if (source.isEmpty())
            return ByteBufferUtil.EMPTY_BYTE_BUFFER;

        BigInteger integerType;

        try
        {
            integerType = new BigInteger(source);
        }
        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));
        }
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Ensure the string contains only an optional +/- sign and decimal digits
  2. Parse floats into DecimalType (decimal) instead of IntegerType (varint)
  3. Strip formatting (spaces, commas) and validate with a regex ^[+-]?\d+$ before calling fromString
  4. Catch MarshalException and report the invalid literal

Example fix

// before
ByteBuffer v = IntegerType.instance.fromString("3.14"); // throws
// after
if (!raw.matches("[+-]?\\d+")) throw new IllegalArgumentException("varint literal required");
ByteBuffer v = IntegerType.instance.fromString("3"); // or DecimalType for 3.14
Defensive patterns

Strategy: validation

Validate before calling

if (!source.matches("[+-]?\\d+"))
    throw new IllegalArgumentException("Not a valid varint literal: " + source);

Type guard

static boolean isBigIntegerLiteral(String s) { try { new BigInteger(s); return true; } catch (NumberFormatException e) { return false; } }

Try / catch

try { IntegerType.instance.fromString(source); } catch (MarshalException e) { /* invalid varint literal; reject or route to decimal type */ }

Prevention

When it happens

Trigger: Calling IntegerType.instance.fromString("12.5") or fromString("") or fromString("0x1F") — new BigInteger throws NumberFormatException, rethrown as MarshalException.

Common situations: Passing decimal floats or hex strings to varint columns; empty strings from blank CSV fields; locale-formatted numbers with grouping separators.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/80286c7889a8d248. Report an issue: GitHub.