{"record":{"id":"5c3a65fcf0043854","repo":"NationalSecurityAgency/ghidra","slug":"given-field-does-not-have-the-given-type","errorCode":null,"errorMessage":"Given field does not have the given type: {} != {}","messagePattern":"Given field does not have the given type: (.+?) != (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStoreFactory.java","lineNumber":337,"sourceCode":"\t\tprotected final int column;\n\n\t\t/**\n\t\t * Construct a codec\n\t\t * \n\t\t * @param valueType\n\t\t * @param objectType\n\t\t * @param fieldType\n\t\t * @param field\n\t\t * @param column\n\t\t */\n\t\tpublic AbstractDBFieldCodec(Class<VT> valueType, Class<OT> objectType, Class<FT> fieldType,\n\t\t\t\tField field, int column) {\n\t\t\tif (!field.getDeclaringClass().isAssignableFrom(objectType)) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Given field does not apply to given object type\");\n\t\t\t}\n\t\t\tif (field.getType() != valueType) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Given field does not have the given type: \" + valueType + \" != \" + field);\n\t\t\t}\n\t\t\tthis.valueType = valueType;\n\t\t\t@SuppressWarnings(\"unchecked\")\n\t\t\tClass<VT> boxedType = (Class<VT>) MethodType.methodType(valueType).wrap().returnType();\n\t\t\tthis.boxedType = boxedType;\n\t\t\tthis.objectType = objectType;\n\t\t\tthis.fieldType = fieldType;\n\t\t\tthis.field = field;\n\t\t\tthis.column = column;\n\t\t}\n\n\t\t@Override\n\t\tpublic void store(OT obj, DBRecord record) {\n\t\t\ttry {\n\t\t\t\tdoStore(obj, record);\n\t\t\t}\n\t\t\tcatch (IllegalArgumentException | IllegalAccessException e) {","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStoreFactory.java#L319-L355","documentation":"Thrown (unchecked IllegalArgumentException) by the AbstractDBFieldCodec constructor when field.getType() != valueType — the reflective field's Java type does not match the codec's declared value type. The codec serialises a specific value type, so the field it operates on must hold exactly that type.","triggerScenarios":"Registering a codec (e.g. a Long codec) against a field whose declared Java type differs (e.g. an Integer or String field), or vice versa. The value type parameter and the field's runtime type must agree.","commonSituations":"Changing a field's Java type (e.g. int -> long) without updating the codec value type; using the wrong codec class for a field; autoboxing confusion (primitive vs boxed) if the codec expects a specific one.","solutions":["Make the codec's value type match field.getType() exactly (derive one from the other).","After changing a field's type, update its codec registration to the matching codec class.","When in doubt, resolve the codec by the field's declared type rather than hardcoding a value type."],"exampleFix":"// before\nnew IntDBFieldCodec<>(OT.class, longField, col); // throws: field is long, codec is int\n\n// after: use the codec matching the field's type\nnew LongDBFieldCodec<>(OT.class, longField, col);","handlingStrategy":"validation","validationCode":"// Ensure the codec value type matches the field's declared type\nif (field.getType() != valueType) {\n    // mismatch: pick the codec whose value type equals field.getType()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the codec's value type to field.getType() exactly.","After changing a field's type, update its codec registration.","Resolve the codec by the field's declared type rather than hardcoding."],"tags":["database","codec","reflection","type-mismatch","illegal-argument","unchecked-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}