apache/cassandra · error · MarshalException

Unable to make short from '%s'

Error message

Unable to make short from '%s'

What it means

ShortType.fromString parses a CQL text literal into a 16-bit short via Short.parseShort. If the string is empty, non-numeric, or out of the -32768..32767 range, the NumberFormatException/NullPointerException is wrapped in a MarshalException with this message.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/ShortType.java:84

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

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

        short s;

        try
        {
            s = Short.parseShort(source);
        }
        catch (Exception e)
        {
            throw new MarshalException(String.format("Unable to make short from '%s'", source), e);
        }

        return decompose(s);
    }

    public Term fromJSONObject(Object parsed) throws MarshalException
    {
        if (parsed instanceof String || parsed instanceof Number)
            return new Constants.Value(fromString(String.valueOf(parsed)));

        throw new MarshalException(String.format(
                "Expected a short value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
    }

    @Override
    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
    {
        return Objects.toString(getSerializer().deserialize(buffer), "\"\"");

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Validate the input matches an integer regex and fits in -32768..32767 before binding.
  2. Catch MarshalException at the statement-construction boundary and surface a field-level validation message.
  3. Use ByteType/IntType instead if the values are not truly smallint-range.

Example fix

// before
short s = Short.parseShort(userInput); // throws on '1.5' or '70000'
// after
if (!userInput.matches("-?\\d+") || Integer.parseInt(userInput) < Short.MIN_VALUE || Integer.parseInt(userInput) > Short.MAX_VALUE)
    throw new IllegalArgumentException("not a smallint: " + userInput);
short s = Short.parseShort(userInput);
Defensive patterns

Strategy: validation

Validate before calling

boolean ok = s != null && s.matches("-?\\d+"); if (ok) { int v = Integer.parseInt(s); ok = v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; }

Try / catch

try { ShortType.instance.fromString(s); } catch (MarshalException e) { /* show field-level error: e.getMessage() */ }

Prevention

When it happens

Trigger: Inserting/binding a value like 'abc', '' or '70000' into a smallint column; calling ShortType.fromString directly; fromJSONObject delegating to fromString with a String or Number that does not parse as a short.

Common situations: User supplies a decimal-with-fraction ("1.5") or a value outside smallint range; locale/formatting code produces '1,234'; empty string from an unset form field.

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/687dc0c841122a99. Report an issue: GitHub.