{"record":{"id":"76e7b2f2921e9461","repo":"xuxueli/xxl-job","slug":"xxl-job-method-jobhandler-initmethod-invalid-for","errorCode":null,"errorMessage":"xxl-job method-jobhandler initMethod invalid, for[{}#{}] .","messagePattern":"xxl-job method-jobhandler initMethod invalid, for\\[(.+?)#(.+?)\\] \\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java","lineNumber":368,"sourceCode":"                    \"The correct method format like \\\" public ReturnT<String> execute(String param) \\\" .\");\n        }\n        if (!method.getReturnType().isAssignableFrom(ReturnT.class)) {\n            throw new RuntimeException(\"xxl-job method-jobhandler return-classtype invalid, for[\" + bean.getClass() + \"#\" + method.getName() + \"] , \" +\n                    \"The correct method format like \\\" public ReturnT<String> execute(String param) \\\" .\");\n        }*/\n\n        executeMethod.setAccessible(true);\n\n        // init and destroy\n        Method initMethod = null;\n        Method destroyMethod = null;\n\n        if (StringTool.isNotBlank(xxlJob.init())) {\n            try {\n                initMethod = clazz.getDeclaredMethod(xxlJob.init());\n                initMethod.setAccessible(true);\n            } catch (NoSuchMethodException e) {\n                throw new RuntimeException(\"xxl-job method-jobhandler initMethod invalid, for[\" + clazz + \"#\" + methodName + \"] .\");\n            }\n        }\n        if (StringTool.isNotBlank(xxlJob.destroy())) {\n            try {\n                destroyMethod = clazz.getDeclaredMethod(xxlJob.destroy());\n                destroyMethod.setAccessible(true);\n            } catch (NoSuchMethodException e) {\n                throw new RuntimeException(\"xxl-job method-jobhandler destroyMethod invalid, for[\" + clazz + \"#\" + methodName + \"] .\");\n            }\n        }\n\n        // registry jobhandler\n        registryJobHandler(name, new MethodJobHandler(bean, executeMethod, initMethod, destroyMethod));\n\n    }\n\n\n    // ---------------------- job thread repository ----------------------","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java#L350-L386","documentation":"Thrown by registryJobHandler when @XxlJob(init=\"...\") names a method that does not exist on the bean's class (NoSuchMethodException caught and rewrapped). The init lifecycle hook must be a declared no-arg method on the same class.","triggerScenarios":"A handler annotated @XxlJob(value=\"x\", init=\"initMe\") where initMe is not declared, has parameters, is on a superclass not seen by getDeclaredMethod, or was renamed/deleted.","commonSituations":"Renamed the init method but not the annotation; declared init with parameters (must be no-arg); method is private on a parent class and getDeclaredMethod only sees the concrete class.","solutions":["Declare a public/package no-arg method whose name matches @XxlJob(init=...).","Keep the init method on the same class that carries the @XxlJob execute method.","Remove init=\"...\" from the annotation if no init lifecycle is needed."],"exampleFix":"// before\n@XxlJob(value=\"x\", init=\"warmUp\")\npublic ReturnT<String> execute(String p){...}\n// no warmUp() method exists\n// after\n@XxlJob(value=\"x\", init=\"warmUp\")\npublic ReturnT<String> execute(String p){...}\npublic void warmUp(){ /* preload */ }","handlingStrategy":"validation","validationCode":"// Verify the init method exists and is no-arg before registration\nif (StringTool.isNotBlank(xxlJob.init())) {\n    Method im = clazz.getDeclaredMethod(xxlJob.init());\n    if (im.getParameterCount() != 0) throw new IllegalStateException(\"init must be no-arg\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    xxlJobExecutor.start();\n} catch (RuntimeException e) {\n    log.error(\"handler init method invalid: {}\", e.getMessage());\n}","preventionTips":["Keep init methods no-arg and on the annotated class.","Update the annotation when renaming lifecycle methods.","Add a test that reflects over @XxlJob handlers and asserts their init/destroy methods exist."],"tags":["jobhandler","annotation","lifecycle","reflection"],"backgroundTag":null,"analyzedSha":"e74c784f68f81fa89cb350913ef15794865d7b12","analyzedAt":"2026-08-14T04:22:43.715Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}