{"record":{"id":"b478307a95202298","repo":"alibaba/canal","slug":"invoke-method-failed","errorCode":null,"errorMessage":"Invoke method failed: '{}' @ {}","messagePattern":"Invoke method failed: '(.+?)' @ (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java","lineNumber":127,"sourceCode":"                            + e.getMessage(),\r\n                    e);\r\n            }\r\n\r\n            return null;\r\n        }\r\n        return conn;\r\n    }\r\n\r\n    private static final Object invokeMethod(Object obj, Class<?> objClazz, String name) {\r\n        try {\r\n            Method method = objClazz.getMethod(name, (Class<?>[]) null);\r\n            return method.invoke(obj, (Object[]) null);\r\n        } catch (NoSuchMethodException e) {\r\n            throw new IllegalArgumentException(\"No such method: \\'\" + name + \"\\' @ \" + objClazz.getName(), e);\r\n        } catch (IllegalAccessException e) {\r\n            throw new IllegalArgumentException(\"Cannot invoke method: \\'\" + name + \"\\' @ \" + objClazz.getName(), e);\r\n        } catch (InvocationTargetException e) {\r\n            throw new IllegalArgumentException(\"Invoke method failed: \\'\" + name + \"\\' @ \" + objClazz.getName(),\r\n                e.getTargetException());\r\n        }\r\n    }\r\n\r\n    private static final Object getDeclaredField(Object obj, Class<?> objClazz, String name) {\r\n        try {\r\n            Field field = objClazz.getDeclaredField(name);\r\n            field.setAccessible(true);\r\n            return field.get(obj);\r\n        } catch (NoSuchFieldException e) {\r\n            throw new IllegalArgumentException(\"No such field: \\'\" + name + \"\\' @ \" + objClazz.getName(), e);\r\n        } catch (IllegalAccessException e) {\r\n            throw new IllegalArgumentException(\"Cannot get field: \\'\" + name + \"\\' @ \" + objClazz.getName(), e);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Connect MySQL master to fetch binlog.\r","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/dbsync/src/main/java/com/taobao/tddl/dbsync/binlog/DirectLogFetcher.java#L109-L145","documentation":"Thrown by invokeMethod() when the reflectively-invoked method itself throws; the original target exception is attached as the cause (getTargetException). The error names which method on which class failed, but the real failure is the wrapped exception.","triggerScenarios":"A reflected method on the mysql driver's Connection/IO object executed and threw an exception (e.g. the connection's underlying IO is closed, a network call failed, or an internal invariant was violated). invokeMethod re-throws as IllegalArgumentException with the target exception as cause.","commonSituations":"The mysql connection passed to DirectLogFetcher.open() was already closed or in a bad state; the driver threw an internal IOException/NPE during the reflected call; transient network reset between client and master.","solutions":["Inspect the cause (e.getCause() / getTargetException) of the IllegalArgumentException - the named method is a symptom, the cause is the real error.","Ensure the Connection passed to open() is open and healthy before calling (validate with a SELECT 1).","If the cause is network-related, retry open() on a fresh connection.","Confirm the driver version's reflected method still behaves as the library assumes."],"exampleFix":"// before\ncatch (IllegalArgumentException e) {\n    throw new RuntimeException(e);\n}\n\n// after - surface the real cause\ncatch (IllegalArgumentException e) {\n    Throwable real = e.getCause() != null ? e.getCause() : e;\n    logger.error(\"Reflected driver call failed: \" + real, real);\n    throw new IOException(\"Driver internal call failed\", real);\n}","handlingStrategy":"try-catch","validationCode":"// Probe the connection is live so the reflected call won't throw internally\nif (!conn.isValid(3)) {\n    throw new IOException(\"connection not valid; driver call would fail\");\n}","typeGuard":null,"tryCatchPattern":"try { fetcher.open(conn, file, pos, serverId, false); }\ncatch (IllegalArgumentException e) {\n    Throwable cause = e.getCause(); // the real getTargetException\n    logger.error(\"reflected driver call failed\", cause);\n    throw new IOException(\"driver internal failure\", cause);\n}","preventionTips":["Always inspect the cause of the wrapped IllegalArgumentException - the named method is secondary.","Pass only freshly-validated, open connections to open().","Log the cause chain so the underlying driver exception is not hidden."],"tags":["binlog","reflection","driver-compat","cause-chain"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}