apache/cassandra · error · InvalidTypeException
Cannot parse 8-bits int value from
Error message
Cannot parse 8-bits int value from "%s"
What it means
InvalidTypeException from TinyIntCodec.parse: the string could not be parsed by Byte.parseByte — either outside the 8-bit signed range (-128..127) or not a numeric literal. Empty strings and 'NULL' (case-insensitive) are handled as null before parsing, so this fires only for malformed or out-of-range input.
Solutions
- Validate the value fits in -128..127 and is an integer before parsing.
- If the data legitimately exceeds the byte range, change the column to smallint/int and use the matching codec.
- Parse as a wider type first (Integer.parseInt) and range-check before narrowing to byte.
- Catch InvalidTypeException and report which input value and expected range failed.
Example fix
// before
Byte b = new ByteCodec().parse(configValue);
// after
int n = Integer.parseInt(configValue.trim());
if (n < -128 || n > 127)
throw new IllegalArgumentException("tinyint out of range: " + n);
Byte b = new ByteCodec().parse(Integer.toString(n)); Defensive patterns
Strategy: validation
Validate before calling
boolean isValidTinyint(String s) {
if (s == null || s.trim().isEmpty() || s.equalsIgnoreCase("NULL")) return true;
try { int n = Integer.parseInt(s.trim()); return n >= -128 && n <= 127; }
catch (NumberFormatException e) { return false; }
} Try / catch
try { Byte b = codec.parse(value); }
catch (InvalidTypeException e) {
throw new IllegalArgumentException("tinyint must be integer in [-128,127]: " + value, e);
} Prevention
- Range-check integers before narrowing to byte.
- Use int/smallint columns for values beyond -128..127.
- Validate numeric config values at startup.
- Parse via Integer.parseInt first, then narrow.
When it happens
Trigger: Calling ByteCodec.parse(String) with values like "256", "-129", "1.5", or "abc"; commonly when binding tinyint values from user input or config strings.
Common situations: Reading a tinyint column whose data actually exceeds the byte range (values stored as larger ints), localized number strings with separators, or config files supplying plain integers larger than 127.
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
- Cannot parse 16-bits int value from
- Cannot parse 32-bits float value from
- Cannot parse inet value from
- inet values must be enclosed in single quotes
- A CQL blob string must have an even length (since one byte…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/c751e5109ce7842c.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/TypeCodec.java:1564
private static final TinyIntCodec instance = new TinyIntCodec();
private TinyIntCodec()
{
super(tinyint());
}
@Override
public Byte parse(String value)
{
try
{
return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")
? null
: Byte.parseByte(value);
}
catch (NumberFormatException e)
{
throw new InvalidTypeException(
String.format("Cannot parse 8-bits int value from \"%s\"", value));
}
}
@Override
public String format(Byte value)
{
if (value == null) return "NULL";
return Byte.toString(value);
}
@Override
public ByteBuffer serializeNoBoxing(byte value, ProtocolVersion protocolVersion)
{
ByteBuffer bb = ByteBuffer.allocate(1);
bb.put(0, value);
return bb;
}View on GitHub (pinned to 88fd0f6a0e)