apache/cassandra · error · MarshalException

Invalid byte for ascii: + Byte.toString(b)

Error message

Invalid byte for ascii: + Byte.toString(b)

What it means

AsciiSerializer.validate rejects any byte with the high bit set: an ascii column may only contain bytes 0-127. MarshalException("Invalid byte for ascii: N") is thrown when a value outside 7-bit ASCII is written or validated against an ascii column.

Source

Thrown at src/java/org/apache/cassandra/serializers/AsciiSerializer.java:40

import org.apache.cassandra.db.marshal.ValueAccessor;

public class AsciiSerializer extends AbstractTextSerializer
{
    public static final AsciiSerializer instance = new AsciiSerializer();

    private AsciiSerializer()
    {
        super(StandardCharsets.US_ASCII);
    }

    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException
    {
        // 0-127
        for (int i=0, size=accessor.size(value); i < size; i++)
        {
            byte b = accessor.getByte(value, i);
            if (b < 0)
                throw new MarshalException("Invalid byte for ascii: " + Byte.toString(b));
        }
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Change the column type from ascii to text: ALTER TABLE t ALTER c TYPE text;
  2. Strip/encode the data client-side before insert (e.g. replace non-ASCII chars or use CharsetEncoder with a replacement).
  3. On the server, handle AsciiType instead of UTF8Type for validation if the data really is 7-bit.
  4. Validate strings in application code before sending to avoid failed writes.

Example fix

// before
String s = "café"; // 'é' is non-ASCII -> MarshalException on ascii column
// after
String s = s.replaceAll("[^\\x00-\\x7F]", "");
// or: ALTER TABLE t ALTER c TYPE text;
Defensive patterns

Strategy: validation

Validate before calling

boolean isAscii = s.chars().allMatch(c -> c < 128); // validate before writing to ascii column

Type guard

static boolean isAscii(String s) { return s != null && StandardCharsets.US_ASCII.newEncoder().canEncode(s); }

Try / catch

try { insertAscii(col, s); } catch (com.datastax.driver.core.exceptions.InvalidQueryException | MarshalException e) { /* non-ASCII data: switch to text column */ }

Prevention

When it happens

Trigger: Inserting a string containing non-ASCII characters (e.g. UTF-8 accented letters, emoji) into a column of type ascii; validate() iterates bytes and throws on the first negative byte (src/java/org/apache/cassandra/serializers/AsciiSerializer.java:40).

Common situations: Internationalized application data written to ascii columns; drivers that don't pre-validate on the client; schema migrations where a text column was recreated as ascii.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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