apache/cassandra · error · MarshalException

Unable to make byte from '%s'

Error message

Unable to make byte from '%s'

What it means

ByteType.fromString throws this when the source string cannot be parsed by Byte.parseByte, i.e. it is not an integer in the signed 8-bit range [-128, 127]. The underlying parse failure (NumberFormatException etc.) is chained as the cause.

Source

Thrown at src/java/org/apache/cassandra/db/marshal/ByteType.java:81

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

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

        byte b;

        try
        {
            b = Byte.parseByte(source);
        }
        catch (Exception e)
        {
            throw new MarshalException(String.format("Unable to make byte from '%s'", source), e);
        }

        return decompose(b);
    }

    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 byte value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
    }

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

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Supply an integer literal within -128..127
  2. Change the column type to smallint/int if larger values are needed
  3. Range-check in application code before casting to byte
  4. Trim the input and reject non-integer strings before binding

Example fix

// before
INSERT INTO t (k, v) VALUES (1, 300); -- byte column
// after
INSERT INTO t (k, v) VALUES (1, 42); -- or ALTER TABLE t ALTER v TYPE int;
Defensive patterns

Strategy: validation

Validate before calling

public static void assertByte(String s) {
    int v = Integer.parseInt(s.trim());
    if (v < Byte.MIN_VALUE || v > Byte.MAX_VALUE)
        throw new IllegalArgumentException("Out of byte range: " + v);
}

Prevention

When it happens

Trigger: INSERT of a value like '300', 'abc', '1.5', or '-200' into a byte column; fromJSONObject passing a numeric string out of byte range; binding values with whitespace or sign errors.

Common situations: Migrating from int columns to byte columns where values exceed 127; typos and decimals in manual cqlsh sessions; application code not validating ranges before bind; CSV imports with unparsed numeric formats.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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