{"record":{"id":"73b7638950dbf0df","repo":"MyCATApache/Mycat-Server","slug":"could-not-invoke-objectclass-methodname","errorCode":null,"errorMessage":"Could not invoke ${objectClass}.${methodName}","messagePattern":"Could not invoke (.+?)\\.(.+?)","errorType":"exception","errorClass":"ObjectAccessException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/util/ReflectionProvider.java","lineNumber":121,"sourceCode":"\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\n    public void invokeMethod(Object object, String methodName, Object value, Class<?> definedIn) {\n        try {\n            Method method = object.getClass().getMethod(methodName, new Class[] { value.getClass() });\n            method.invoke(object, new Object[] { value });\n        } catch (Exception e) {\n            throw new ObjectAccessException(\"Could not invoke \" + object.getClass() + \".\" + methodName, e);\n        }\n    }\n\n    public Class<?> getFieldType(Object object, String fieldName, Class<?> definedIn) {\n        return fieldDictionary.field(object.getClass(), fieldName, definedIn).getType();\n    }\n\n    public boolean fieldDefinedInClass(String fieldName, Class<?> type) {\n        try {\n            Field field = fieldDictionary.field(type, fieldName, null);\n            return fieldModifiersSupported(field);\n        } catch (ObjectAccessException e) {\n            return false;\n        }\n    }\n\n    public Field getField(Class<?> definedIn, String fieldName) {\n        return fieldDictionary.field(definedIn, fieldName, null);","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/util/ReflectionProvider.java#L103-L139","documentation":"invokeMethod reflects a setter method on the object and invokes it with a single value argument. Any failure inside the try block (NoSuchMethodException, wrong argument type, target invocation exception) is wrapped as ObjectAccessException 'Could not invoke <class>.<method>'. It signals the setter could not be located or the invocation itself failed.","triggerScenarios":"object.getClass().getMethod(methodName, value.getClass()) finds no method with that exact signature, or method.invoke throws (wrong value type, method threw internally, access denied). Note the lookup uses value.getClass() exactly, so overloaded setters or primitive/boxed mismatches fail.","commonSituations":"Setter expects a primitive (setPort(int)) but a boxed Integer lookup is used (or vice versa); method name typo in configuration; setter's parameter is a supertype/interface so exact-class getMethod fails.","solutions":["Ensure a public method exists with signature exactly <name>(<value.getClass()>) — getMethod is exact-match","Use the boxed type matching the setter parameter (e.g. Integer.class for int) or iterate getMethods() to find an assignable match","Inspect e.getCause() (InvocationTargetException) for an exception thrown inside the setter itself","Rename the configured property to the actual setter name"],"exampleFix":"// before\nprovider.invokeMethod(obj, \"setPort\", 8080, null); // setter is setPort(int), exact lookup ok, but setter is named setListenPort\n// after\nprovider.invokeMethod(obj, \"setListenPort\", 8080, null);","handlingStrategy":"validation","validationCode":"try {\n    obj.getClass().getMethod(methodName, value.getClass());\n} catch (NoSuchMethodException e) {\n    throw new IllegalArgumentException(\"no method \" + methodName + \"(\" + value.getClass().getName() + \") on \" + obj.getClass());\n}","typeGuard":"boolean hasSetter = java.util.Arrays.stream(obj.getClass().getMethods())\n    .anyMatch(m -> m.getName().equals(methodName)\n        && m.getParameterCount() == 1\n        && m.getParameterTypes()[0].isAssignableFrom(value.getClass()));","tryCatchPattern":"try {\n    provider.invokeMethod(obj, methodName, value, definedIn);\n} catch (ObjectAccessException e) {\n    Throwable cause = e.getCause();\n    log.error(\"invoke {} failed ({}): {}\", methodName, cause, cause != null ? cause.getCause() : null);\n}","preventionTips":["Match exact setter signature including boxing (int vs Integer)","Remember getMethod is exact-match, not assignable-match","Check InvocationTargetException cause for setter-internal failures","Verify method names in config files against real class setters"],"tags":["reflection","method-invocation","setter"],"backgroundTag":"method-not-implemented","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"}