{"record":{"id":"818fe8d269b5b52b","repo":"NationalSecurityAgency/ghidra","slug":"column-is-not-of-type-it-is","errorCode":null,"errorMessage":"Column {} is not of type {}! It is {}","messagePattern":"Column (.+?) is not of type (.+?)! It is (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStore.java","lineNumber":1005,"sourceCode":"\t/**\n\t * Get the table index for the given column number\n\t * \n\t * @param <K> the type of the object field for the indexed column\n\t * @param fieldClass the class specifying {@link K}\n\t * @param columnIndex the column number\n\t * @return the index\n\t * @throws IllegalArgumentException if the column has a different type than {@link K}\n\t */\n\tprotected <K> DBCachedObjectIndex<K, T> getIndex(Class<K> fieldClass, int columnIndex) {\n\t\tif (!ArrayUtils.contains(table.getIndexedColumns(), columnIndex)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Column \" + schema.getFieldNames()[columnIndex] + \" is not indexed\");\n\t\t}\n\n\t\tDBFieldCodec<?, T, ?> codec = codecs.get(columnIndex);\n\t\tClass<?> exp = codec.getValueType();\n\t\tif (fieldClass != exp) {\n\t\t\tthrow new IllegalArgumentException(\"Column \" + schema.getFieldNames()[columnIndex] +\n\t\t\t\t\" is not of type \" + fieldClass + \"! It is \" + exp);\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tDBFieldCodec<K, T, ?> castCodec = (DBFieldCodec<K, T, ?>) codec;\n\t\treturn new DBCachedObjectIndex<>(this, adapter, castCodec, columnIndex, FieldSpan.ALL,\n\t\t\tDirection.FORWARD);\n\t}\n\n\t/**\n\t * Get the index for a given column\n\t * \n\t * <p>\n\t * See {@link DBCachedObjectStoreFactory} for an example that includes use of an index\n\t * \n\t * @param <K> the type of the object field for the indexed column\n\t * @param fieldClass the class specifying {@link K}\n\t * @param column the indexed column\n\t * @return the index","sourceCodeStart":987,"sourceCodeEnd":1023,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStore.java#L987-L1023","documentation":"Thrown (unchecked IllegalArgumentException) by getIndex(fieldClass, columnIndex) when the fieldClass passed by the caller does not match the column codec's actual value type (codec.getValueType()). The index is typed by its codec; requesting it with the wrong type would cause unsafe casts, so the type is verified.","triggerScenarios":"Calling getIndex(Long.class, col) on a column whose codec value type is String (or vice versa) — a type/class mismatch between what the caller believes the column stores and its declared codec type.","commonSituations":"Schema/column-type confusion; refactoring a field's type but not updating the index lookup call; copy-pasting an index request from a different column; using a boxed type where primitive-backed type is expected or the reverse.","solutions":["Match fieldClass to the column's codec value type (inspect codec.getValueType() or the declared field type).","Keep a single source of truth for each column's type and derive both the schema declaration and the index request from it.","After changing a field's type, update every getIndex call site that references that column."],"exampleFix":"// before\nDBCachedObjectIndex<Long,T> idx = store.getIndex(Long.class, nameCol); // throws if column is String-typed\n\n// after: use the column's actual value type\nClass<?> actual = store.getCodec(nameCol).getValueType();\nDBCachedObjectIndex<?,T> idx = store.getIndex(actual, nameCol);","handlingStrategy":"validation","validationCode":"// Match fieldClass to the column's codec value type\nClass<?> actual = codecs.get(columnIndex).getValueType();\nif (fieldClass != actual) {\n    // type mismatch: pass `actual` (or align the schema) instead\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive fieldClass from the column's codec value type.","Keep one source of truth per column type shared by schema and index calls.","Update index call sites after changing a field's type."],"tags":["database","index","type-mismatch","codec","illegal-argument","unchecked-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}