{"record":{"id":"93fdae5b7b906220","repo":"apache/cassandra","slug":"value-s-is-of-type-s-not-s","errorCode":null,"errorMessage":"Value %s is of type %s, not %s","messagePattern":"Value (.+?) is of type (.+?), not (.+?)","errorType":"exception","errorClass":"InvalidTypeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/types/AbstractGettableByIndexData.java","lineNumber":98,"sourceCode":"    {\n        return getCodecRegistry().codecFor(getType(i), javaClass);\n    }\n\n    protected <T> TypeCodec<T> codecFor(int i, TypeToken<T> javaType)\n    {\n        return getCodecRegistry().codecFor(getType(i), javaType);\n    }\n\n    protected <T> TypeCodec<T> codecFor(int i, T value)\n    {\n        return getCodecRegistry().codecFor(getType(i), value);\n    }\n\n    void checkType(int i, DataType.Name actual)\n    {\n        DataType.Name expected = getType(i).getName();\n        if (!actual.isCompatibleWith(expected))\n            throw new InvalidTypeException(\n            String.format(\"Value %s is of type %s, not %s\", getName(i), expected, actual));\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public boolean isNull(int i)\n    {\n        return getValue(i) == null;\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    @Override\n    public boolean getBool(int i)\n    {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/types/AbstractGettableByIndexData.java#L80-L116","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nString name = row.getString(\"age\"); // age is int\n// after\nint age = row.getInt(\"age\");","handlingStrategy":"type-guard","validationCode":"DataType.Name actual = row.getColumnDefinitions().getType(i).getName();\nboolean safe = actual.isCompatibleWith(DataType.Name.TEXT); // check before getString(i)","typeGuard":"static String safeGetString(Row row, int i) {\n    if (row.getColumnDefinitions().getType(i).getName().isCompatibleWith(DataType.Name.TEXT)) {\n        return row.getString(i);\n    }\n    return null;\n}","tryCatchPattern":"try {\n    return row.getString(i);\n} catch (InvalidTypeException e) {\n    // log row type metadata and use the matching getter\n    return null;\n}","preventionTips":["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"],"tags":["java-driver","cql","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}