{"record":{"id":"c1fc4dac79218ffa","repo":"MyCATApache/Mycat-Server","slug":"could-not-get-field-fieldclass-fieldname","errorCode":null,"errorMessage":"Could not get field ${fieldClass}.${fieldName}","messagePattern":"Could not get field (.+?)\\.(.+?)","errorType":"exception","errorClass":"ObjectAccessException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/util/ReflectionProvider.java","lineNumber":97,"sourceCode":"            } else {\n                throw new ObjectAccessException(\"Constructor for \" + type.getName() + \" threw an exception\",\n                        e.getTargetException());\n            }\n        }\n    }\n\n    public void visitSerializableFields(Object object, Visitor visitor) {\n        for (Iterator<Field> iterator = fieldDictionary.serializableFieldsFor(object.getClass()); iterator.hasNext();) {\n            Field field = iterator.next();\n            if (!fieldModifiersSupported(field)) {\n                continue;\n            }\n            validateFieldAccess(field);\n            try {\n                Object value = field.get(object);\n                visitor.visit(field.getName(), field.getType(), field.getDeclaringClass(), value);\n            } catch (IllegalArgumentException e) {\n                throw new ObjectAccessException(\"Could not get field \" + field.getClass() + \".\" + field.getName(), e);\n            } catch (IllegalAccessException e) {\n                throw new ObjectAccessException(\"Could not get field \" + field.getClass() + \".\" + field.getName(), e);\n            }\n        }\n    }\n\n    public void writeField(Object object, String fieldName, Object value, Class<?> definedIn) {\n        Field field = fieldDictionary.field(object.getClass(), fieldName, definedIn);\n        validateFieldAccess(field);\n        try {\n            field.set(object, value);\n        } catch (IllegalArgumentException e) {\n            throw new ObjectAccessException(\"Could not set field \" + field.getName() + \"@\" + object.getClass(), e);\n        } catch (IllegalAccessException e) {\n            throw new ObjectAccessException(\"Could not set field \" + field.getName() + \"@\" + object.getClass(), e);\n        }\n    }\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/util/ReflectionProvider.java#L79-L115","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)"],"exampleFix":"// before\nprovider.visitSerializableFields(null, visitor); // IllegalArgumentException\n// after\nif (obj == null) { throw new IllegalArgumentException(\"object required\"); }\nprovider.visitSerializableFields(obj, visitor);","handlingStrategy":"validation","validationCode":"if (object == null) throw new IllegalArgumentException(\"visitSerializableFields: object is null\");\nif (!field.getDeclaringClass().isInstance(object)) throw new IllegalArgumentException(object.getClass() + \" is not a \" + field.getDeclaringClass());","typeGuard":null,"tryCatchPattern":"try { provider.visitSerializableFields(obj, visitor); } catch (ObjectAccessException e) { log.error(\"field visit failed: {} (check cause)\", e.getMessage(), e.getCause()); throw e; }","preventionTips":["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"],"tags":["reflection","field-access","serialization"],"backgroundTag":"permission-denied","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}