xuxueli/xxl-job · error · IllegalArgumentException

>>>>>>>>>>> xxl-glue, loadNewInstance error, instance is nul

Error message

>>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null

What it means

Thrown by GlueFactory.loadNewInstance as IllegalArgumentException when no glue instance could be produced: the codeSource was blank, or getCodeSourceClass returned null (e.g. Groovy parsing failed silently upstream). It is the fallback for any path that did not yield a class+instance.

Source

Thrown at xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java:66

	 *
	 * @param codeSource  code source
	 * @return IJobHandler
	 */
	public IJobHandler loadNewInstance(String codeSource) throws Exception{
		if (StringTool.isNotBlank(codeSource)) {
			Class<?> clazz = getCodeSourceClass(codeSource);
			if (clazz != null) {
				Object instance = clazz.newInstance();
                if (instance instanceof IJobHandler) {
                    this.injectService(instance);
                    return (IJobHandler) instance;
                } else {
                    throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, "
                            + "cannot convert from instance[" + instance.getClass() + "] to IJobHandler");
                }
            }
		}
		throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null");
	}
	private Class<?> getCodeSourceClass(String codeSource){
		try {
			// md5
			byte[] md5 = MessageDigest.getInstance("MD5").digest(codeSource.getBytes());
			String md5Str = new BigInteger(1, md5).toString(16);

			Class<?> clazz = CLASS_CACHE.get(md5Str);
			if(clazz == null){
				clazz = groovyClassLoader.parseClass(codeSource);
				CLASS_CACHE.putIfAbsent(md5Str, clazz);
			}
			return clazz;
		} catch (Exception e) {
			return groovyClassLoader.parseClass(codeSource);
		}
	}

View on GitHub (pinned to e74c784f68)

Solutions

  1. Provide non-blank, syntactically valid glue source before loading.
  2. Check the admin console: ensure the glue script is saved and compiles (no Groovy syntax errors).
  3. Verify getCodeSourceClass/groovyClassLoader.parseClass logs for the underlying compile failure.

Example fix

// before
factory.loadNewInstance(""); // blank source
// after
factory.loadNewInstance(validGroovySource); // non-empty, compiling class
Defensive patterns

Strategy: validation

Validate before calling

if (StringTool.isBlank(codeSource)) {
    throw new IllegalArgumentException("glue codeSource is empty");
}

Try / catch

try {
    IJobHandler h = glueFactory.loadNewInstance(codeSource);
} catch (IllegalArgumentException e) {
    log.error("glue load failed (no instance): {}", e.getMessage());
}

Prevention

When it happens

Trigger: Calling loadNewInstance with a null/blank codeSource, or with source whose class failed to load (getCodeSourceClass returned null). The final throw fires because clazz remained null.

Common situations: Glue source cleared or never saved; a Groovy compile error left CLASS_CACHE empty for that md5; a stale/empty glue record triggered a reload.

Related errors


AI-assisted analysis of xuxueli/xxl-job@e74c784f68 (2026-08-14). Data as JSON: /api/errors/d43d496d9f8e7c0e. Report an issue: GitHub.