NationalSecurityAgency/ghidra · error · IllegalArgumentException
Given field does not have the given type: {} != {}
Error message
Given field does not have the given type: {} != {} What it means
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.
Source
Thrown at Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStoreFactory.java:337
protected final int column;
/**
* Construct a codec
*
* @param valueType
* @param objectType
* @param fieldType
* @param field
* @param column
*/
public AbstractDBFieldCodec(Class<VT> valueType, Class<OT> objectType, Class<FT> fieldType,
Field field, int column) {
if (!field.getDeclaringClass().isAssignableFrom(objectType)) {
throw new IllegalArgumentException(
"Given field does not apply to given object type");
}
if (field.getType() != valueType) {
throw new IllegalArgumentException(
"Given field does not have the given type: " + valueType + " != " + field);
}
this.valueType = valueType;
@SuppressWarnings("unchecked")
Class<VT> boxedType = (Class<VT>) MethodType.methodType(valueType).wrap().returnType();
this.boxedType = boxedType;
this.objectType = objectType;
this.fieldType = fieldType;
this.field = field;
this.column = column;
}
@Override
public void store(OT obj, DBRecord record) {
try {
doStore(obj, record);
}
catch (IllegalArgumentException | IllegalAccessException e) {View on GitHub (pinned to d5f144c24d)
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.
Example fix
// before new IntDBFieldCodec<>(OT.class, longField, col); // throws: field is long, codec is int // after: use the codec matching the field's type new LongDBFieldCodec<>(OT.class, longField, col);
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the codec value type matches the field's declared type
if (field.getType() != valueType) {
// mismatch: pick the codec whose value type equals field.getType()
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Column {} is not of type {}! It is {}
- Given field does not apply to given object type
- Too many constants in {} to encode as a byte
- No variant codec for class {}
- No variant codec with selector {}
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/5c3a65fcf0043854.
Report an issue: GitHub.