MyCATApache/Mycat-Server · error · ObjectAccessException
Could not get field .
Error message
Could not get field ${fieldClass}.${fieldName} What it means
ReflectionProvider.visitSerializableFields reads each field's value reflectively and wraps IllegalArgumentException/IllegalAccessException from Field.get() in ObjectAccessException('Could not get field <class>.<name>'). Note it uses field.getClass() (the java.lang.reflect.Field class) rather than the declaring class, so the message shows java.lang.reflect.Field — a cosmetic bug — but the cause is an inaccessible or type-mismatched field read.
Solutions
- Ensure the object passed to visitSerializableFields is a proper instance whose class hierarchy contains the visited fields (pass the correct object, not null or a proxy)
- Make the fields accessible (public) or grant setAccessible permissions / correct JPMS module-opens
- Inspect the wrapped cause to determine whether it is IllegalArgumentException (wrong object) vs IllegalAccessException (access denied)
Example fix
// before
provider.visitSerializableFields(null, visitor); // IllegalArgumentException
// after
if (obj == null) { throw new IllegalArgumentException("object required"); }
provider.visitSerializableFields(obj, visitor); Defensive patterns
Strategy: validation
Validate before calling
if (object == null) throw new IllegalArgumentException("visitSerializableFields: object is null");
if (!field.getDeclaringClass().isInstance(object)) throw new IllegalArgumentException(object.getClass() + " is not a " + field.getDeclaringClass()); Try / catch
try { provider.visitSerializableFields(obj, visitor); } catch (ObjectAccessException e) { log.error("field visit failed: {} (check cause)", e.getMessage(), e.getCause()); throw e; } Prevention
- Never pass null or a proxy to visitSerializableFields
- Keep visited fields non-final and accessible, or grant setAccessible
- Verify object class matches the fields' declaring class before reflection walks
When it happens
Trigger: Calling visitSerializableFields(object, visitor) where a field is final/static-incompatible for get(), the object is not an instance of the field's declaring class (IllegalArgumentException), or field access is blocked (IllegalAccessException).
Common situations: Serializing an object whose runtime class does not match the field's declaring class hierarchy; visiting fields on a proxy or mismatched instance; reflective access denied by module system/SecurityManager; passing null object.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- No such field .
- Cannot create by JDK serialization
- Tried to send an out-of-range integer as a 2-byte value
- rule function must implements
- Cannot construct as it does not have a no-args constructor
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/c1fc4dac79218ffa.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/util/ReflectionProvider.java:97
} else {
throw new ObjectAccessException("Constructor for " + type.getName() + " threw an exception",
e.getTargetException());
}
}
}
public void visitSerializableFields(Object object, Visitor visitor) {
for (Iterator<Field> iterator = fieldDictionary.serializableFieldsFor(object.getClass()); iterator.hasNext();) {
Field field = iterator.next();
if (!fieldModifiersSupported(field)) {
continue;
}
validateFieldAccess(field);
try {
Object value = field.get(object);
visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value);
} catch (IllegalArgumentException e) {
throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
} catch (IllegalAccessException e) {
throw new ObjectAccessException("Could not get field " + field.getClass() + "." + field.getName(), e);
}
}
}
public void writeField(Object object, String fieldName, Object value, Class<?> definedIn) {
Field field = fieldDictionary.field(object.getClass(), fieldName, definedIn);
validateFieldAccess(field);
try {
field.set(object, value);
} catch (IllegalArgumentException e) {
throw new ObjectAccessException("Could not set field " + field.getName() + "@" + object.getClass(), e);
} catch (IllegalAccessException e) {
throw new ObjectAccessException("Could not set field " + field.getName() + "@" + object.getClass(), e);
}
}
View on GitHub (pinned to 65f8d8beb7)