apache/cassandra · error · InvalidTypeException
Value is of type , not
Error message
Value %s is of type %s, not %s
What it means
In the Cassandra Java driver's AbstractGettableByIndexData, checkType validates that the requested column's CQL type is compatible with the getter being used (get(i, X.class) or getX(i)). When the actual value's type is not compatible with the expected type, it throws InvalidTypeException with this message naming the column and both types.
Solutions
- Use the getter matching the column's actual CQL type (getInt for int, getString for text, etc.)
- Read the correct column index/name — verify with the SELECT statement or row.getColumnDefinitions()
- After schema changes, rebuild prepared statements/metadata so row type info is fresh
Example fix
// before
String name = row.getString("age"); // age is int
// after
int age = row.getInt("age"); Defensive patterns
Strategy: type-guard
Validate before calling
DataType.Name actual = row.getColumnDefinitions().getType(i).getName(); boolean safe = actual.isCompatibleWith(DataType.Name.TEXT); // check before getString(i)
Type guard
static String safeGetString(Row row, int i) {
if (row.getColumnDefinitions().getType(i).getName().isCompatibleWith(DataType.Name.TEXT)) {
return row.getString(i);
}
return null;
} Try / catch
try {
return row.getString(i);
} catch (InvalidTypeException e) {
// log row type metadata and use the matching getter
return null;
} Prevention
- Derive getters from getColumnDefinitions() types instead of hardcoding
- Refresh prepared statement metadata after any ALTER TABLE
- Select columns explicitly by name so indexes never drift from expectations
When it happens
Trigger: Calling row.getString(0) on an int column, row.getInt(i) on a text column, or get(i, Float.class) on a double column; using stale Row metadata after a schema change (e.g. column altered from text to int).
Common situations: Schema evolution where column types changed after deployment; miscounting column indexes and hitting a different column than expected; casting results between result sets from differently typed queries.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot assign value to of type
- Cannot assign value to of type
- Cannot cast value to type
- Cannot replace aggregate
- Cannot replace function
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/93fdae5b7b906220.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/functions/types/AbstractGettableByIndexData.java:98
{
return getCodecRegistry().codecFor(getType(i), javaClass);
}
protected <T> TypeCodec<T> codecFor(int i, TypeToken<T> javaType)
{
return getCodecRegistry().codecFor(getType(i), javaType);
}
protected <T> TypeCodec<T> codecFor(int i, T value)
{
return getCodecRegistry().codecFor(getType(i), value);
}
void checkType(int i, DataType.Name actual)
{
DataType.Name expected = getType(i).getName();
if (!actual.isCompatibleWith(expected))
throw new InvalidTypeException(
String.format("Value %s is of type %s, not %s", getName(i), expected, actual));
}
/**
* {@inheritDoc}
*/
@Override
public boolean isNull(int i)
{
return getValue(i) == null;
}
/**
* {@inheritDoc}
*/
@Override
public boolean getBool(int i)
{View on GitHub (pinned to 88fd0f6a0e)