apache/cassandra · error · MarshalException

Unable to make int from '%s'

Error message

Unable to make int from '%s'

What it means

Int32Type.fromString() parses a 32-bit integer from its string form with Integer.parseInt; any parse failure (non-numeric text or values outside int range) is wrapped in this MarshalException with the offending source. The underlying exception (NumberFormatException) is attached as the cause.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/Int32Type.java:99

    {
        return ByteSourceInverse.getOptionalSignedFixedLength(accessor, comparableBytes, 4);
    }

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

        int int32Type;

        try
        {
            int32Type = Integer.parseInt(source);
        }
        catch (Exception e)
        {
            throw new MarshalException(String.format("Unable to make int from '%s'", source), e);
        }

        return decompose(int32Type);
    }

    @Override
    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        try
        {
            if (parsed instanceof String)
                return new Constants.Value(fromString((String) parsed));

            Number parsedNumber = (Number) parsed;
            if (!(parsedNumber instanceof Integer))
                throw new MarshalException(String.format("Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));

            return new Constants.Value(getSerializer().serialize(parsedNumber.intValue()));

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Validate the string matches an optional-sign digit sequence and fits in int range before calling fromString
  2. Use LongType/IntegerType (varint) for values beyond int range
  3. Trim/clean whitespace and thousands separators from input before parsing
  4. Catch MarshalException and report the invalid literal to the caller

Example fix

// before
ByteBuffer v = Int32Type.instance.fromString("1,000"); // throws
// after
String s = raw.trim().replace(",", "");
int n = Integer.parseInt(s); // validate first; fits in int
ByteBuffer v = Int32Type.instance.fromString(String.valueOf(n));
Defensive patterns

Strategy: validation

Validate before calling

try { Integer.parseInt(source.trim()); } catch (NumberFormatException e) { throw new IllegalArgumentException("Not a valid 32-bit int: " + source); }

Type guard

static boolean isInt32Literal(String s) { try { Integer.parseInt(s.trim()); return true; } catch (NumberFormatException e) { return false; } }

Try / catch

try { Int32Type.instance.fromString(source); } catch (MarshalException e) { /* report invalid int literal; check cause for range vs format */ }

Prevention

When it happens

Trigger: Calling Int32Type.instance.fromString("abc") or fromString("99999999999") (overflow) directly or via fromJSONObject; Integer.parseInt throws and the catch block raises MarshalException.

Common situations: User input placed directly into int columns via cqlsh or drivers using the text protocol; CSV/JSON imports with empty or decorated numeric strings ('1,000', '12 '); using bigint-scale numbers in an int column.

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


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