NationalSecurityAgency/ghidra · error · IllegalArgumentException
Given field does not apply to given object type
Error message
Given field does not apply to given object type
What it means
Thrown (unchecked IllegalArgumentException) by the AbstractDBFieldCodec constructor when the reflective Field's declaring class is not assignable from the object type (OT). A codec reads/writes a field on instances of OT, so the field must actually belong to (or be compatible with) that object class; otherwise the field could not be accessed on OT instances.
Source
Thrown at Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBCachedObjectStoreFactory.java:333
protected final Class<VT> boxedType;
protected final Class<OT> objectType;
protected final Class<FT> fieldType;
protected final Field field;
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) {View on GitHub (pinned to d5f144c24d)
Solutions
- Use a Field obtained from the same class (or a supertype) that OT extends — ensure field.getDeclaringClass().isAssignableFrom(objectType).
- Resolve the Field via the object class's own reflection (OT.class.getDeclaredField(...)) so the declaring class always matches.
- After class-hierarchy refactors, regenerate/audit codec registrations for moved fields.
Example fix
// before
new StringDBFieldCodec<>(WrongType.class, WrongType.class.getDeclaredField("name"), col);
// throws if WrongType is not the object type
// after: obtain the field from the actual object type
Field f = MyObject.class.getDeclaredField("name");
new StringDBFieldCodec<>(MyObject.class, f, col); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the Field belongs to (a supertype of) the object type
if (!field.getDeclaringClass().isAssignableFrom(objectType)) {
// wrong field/object pairing: resolve the field from objectType's hierarchy
} Prevention
- Obtain the Field via reflection on the actual object type (or its supertype).
- After class-hierarchy refactors, re-audit codec registrations for moved fields.
- Don't mix fields from sibling annotated classes.
When it happens
Trigger: Registering a codec that pairs a Field from class A with an object type class B where A is not in B's hierarchy — e.g. passing a field declared on a sibling/parent class that OT does not extend, or wiring a field from the wrong annotated class.
Common situations: Refactoring an annotated object class hierarchy so a field moved between classes but the codec registration kept the old Field; copy-pasting codec setup across classes; mixing up two similarly-named annotated object types.
Related errors
- Given field does not have the given type: {} != {}
- Column {} is not of type {}! It is {}
- 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/f6b503e6b07f45b4.
Report an issue: GitHub.