{"record":{"id":"6455d9101ba80c57","repo":"xuxueli/xxl-job","slug":"xxl-glue-loadnewinstance-error-canno","errorCode":null,"errorMessage":">>>>>>>>>>> xxl-glue, loadNewInstance error, cannot convert from instance[{}] to IJobHandler","messagePattern":">>>>>>>>>>> xxl-glue, loadNewInstance error, cannot convert from instance\\[(.+?)\\] to IJobHandler","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java","lineNumber":61,"sourceCode":"\tprivate final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();\r\n\tprivate final ConcurrentMap<String, Class<?>> CLASS_CACHE = new ConcurrentHashMap<>();\r\n\r\n\t/**\r\n\t * load new instance, prototype\r\n\t *\r\n\t * @param codeSource  code source\r\n\t * @return IJobHandler\r\n\t */\r\n\tpublic IJobHandler loadNewInstance(String codeSource) throws Exception{\r\n\t\tif (StringTool.isNotBlank(codeSource)) {\r\n\t\t\tClass<?> clazz = getCodeSourceClass(codeSource);\r\n\t\t\tif (clazz != null) {\r\n\t\t\t\tObject instance = clazz.newInstance();\r\n                if (instance instanceof IJobHandler) {\r\n                    this.injectService(instance);\r\n                    return (IJobHandler) instance;\r\n                } else {\r\n                    throw new IllegalArgumentException(\">>>>>>>>>>> xxl-glue, loadNewInstance error, \"\r\n                            + \"cannot convert from instance[\" + instance.getClass() + \"] to IJobHandler\");\r\n                }\r\n            }\r\n\t\t}\r\n\t\tthrow new IllegalArgumentException(\">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null\");\r\n\t}\r\n\tprivate Class<?> getCodeSourceClass(String codeSource){\r\n\t\ttry {\r\n\t\t\t// md5\r\n\t\t\tbyte[] md5 = MessageDigest.getInstance(\"MD5\").digest(codeSource.getBytes());\r\n\t\t\tString md5Str = new BigInteger(1, md5).toString(16);\r\n\r\n\t\t\tClass<?> clazz = CLASS_CACHE.get(md5Str);\r\n\t\t\tif(clazz == null){\r\n\t\t\t\tclazz = groovyClassLoader.parseClass(codeSource);\r\n\t\t\t\tCLASS_CACHE.putIfAbsent(md5Str, clazz);\r\n\t\t\t}\r\n\t\t\treturn clazz;\r","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java#L43-L79","documentation":"Thrown by GlueFactory.loadNewInstance as IllegalArgumentException when a glue source class was compiled and instantiated but does not implement IJobHandler. Glue jobs must be executable handlers, so the loaded type is rejected after instantiation.","triggerScenarios":"Saving/running a glue script whose class (or its hierarchy) does not implement com.xxl.job.core.handler.IJobHandler; the class loads via the Groovy classloader, instantiates, then fails the instanceof check.","commonSituations":"Edited a glue script and removed 'implements IJobHandler'; pasted a plain Groovy class; renamed the execute contract; glue code compiled against an incompatible xxl-job-core version.","solutions":["Make the glue class implement IJobHandler and provide the required execute method.","Ensure the script imports com.xxl.job.core.handler.IJobHandler (and ReturnT) from the matching core version.","Re-save the corrected glue source so GlueFactory reloads a fresh class."],"exampleFix":"// before - plain class, no handler interface\nclass MyJob {\n    def run(){ ... }\n}\n// after\nclass MyJob implements com.xxl.job.core.handler.IJobHandler {\n    @Override\n    public com.xxl.job.core.router.model.ReturnT<String> execute(String param){ ... }\n}","handlingStrategy":"type-guard","validationCode":"Class<?> clazz = getCodeSourceClass(codeSource);\nif (clazz == null || !IJobHandler.class.isAssignableFrom(clazz)) {\n    throw new IllegalArgumentException(\"glue class must implement IJobHandler: \" + clazz);\n}","typeGuard":"boolean isHandler(Class<?> c) {\n    return c != null && com.xxl.job.core.handler.IJobHandler.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n    IJobHandler h = glueFactory.loadNewInstance(codeSource);\n} catch (IllegalArgumentException e) {\n    log.error(\"glue load failed: {}\", e.getMessage());\n}","preventionTips":["Glue classes must implement IJobHandler and define the execute contract.","Validate glue source in a sandbox compile before publishing.","Keep glue imports aligned with the deployed xxl-job-core version."],"tags":["glue","groovy","jobhandler","scripting","reflection"],"backgroundTag":null,"analyzedSha":"e74c784f68f81fa89cb350913ef15794865d7b12","analyzedAt":"2026-08-14T04:22:43.715Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}