apache/dubbo · error · IllegalStateException
Failed to compile class, cause: {}, class: {}, code: {} , s
Error message
Failed to compile class, cause: {}, class: {}, code:
{}
, stack: {} What it means
Thrown by AbstractCompiler.compile when doCompile (the subclass-specific compilation step) raises a checked Throwable that is not a RuntimeException. The original cause, class name, full source, and stack trace are bundled into an IllegalStateException for diagnostics.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/AbstractCompiler.java:74
String className = pkg != null && pkg.length() > 0 ? pkg + "." + cls : cls;
Lock lock = CLASS_IN_CREATION_MAP.get(className);
if (lock == null) {
CLASS_IN_CREATION_MAP.putIfAbsent(className, new ReentrantLock());
lock = CLASS_IN_CREATION_MAP.get(className);
}
try {
lock.lock();
return Class.forName(className, true, classLoader);
} catch (ClassNotFoundException e) {
if (!code.endsWith("}")) {
throw new IllegalStateException("The java code not endsWith \"}\", code: \n" + code + "\n");
}
try {
return doCompile(neighbor, classLoader, className, code);
} catch (RuntimeException t) {
throw t;
} catch (Throwable t) {
throw new IllegalStateException("Failed to compile class, cause: " + t.getMessage() + ", class: "
+ className + ", code: \n" + code + "\n, stack: " + ClassUtils.toString(t));
}
} finally {
lock.unlock();
}
}
protected Class<?> doCompile(ClassLoader classLoader, String name, String source) throws Throwable {
return null;
}
protected Class<?> doCompile(Class<?> neighbor, ClassLoader classLoader, String name, String source)
throws Throwable {
return doCompile(classLoader, name, source);
}
}
View on GitHub (pinned to 3a3043227f)
Solutions
- Read the cause message and stack in the exception — it identifies the real compilation problem.
- Fix the generated source (syntax error, missing import, undefined reference) that the cause describes.
- Ensure all classes referenced by the generated source are on the compilation classpath.
- Verify the compiler implementation (JdkCompiler vs JavassistCompiler) matches your JVM/toolchain.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate the generated source for obvious errors before compiling
if (code == null || code.isEmpty() || !code.contains("class ")) {
throw new IllegalArgumentException("invalid generated source");
} Try / catch
try {
compiler.compile(neighbor, code, classLoader);
} catch (IllegalStateException e) {
// inspect e.getMessage() for the cause, class, and source; fix the generated code
} Prevention
- Read the cause message in the wrapped exception to find the real compile error.
- Ensure all classes referenced by generated source are on the classpath.
- Unit-test code generators against expected output.
- Match the compiler implementation to the running JDK/toolchain.
When it happens
Trigger: The concrete compiler (JdkCompiler, JavassistCompiler) threw an exception during the actual compile/load step — e.g. a syntax error, missing dependency, classloader failure, or tooling error. RuntimeExceptions propagate unchanged; everything else is wrapped here.
Common situations: Generated SPI/Adaptive extension source has a genuine compile error (undefined symbol, bad syntax). The compiler cannot access a required class on the classpath. Javassist/JDK compiler tooling version mismatch or configuration issue.
Related errors
- No such class name in {}
- Compilation failed. class: {}, diagnostics: {}
- The java code not endsWith "}", code: {}
- The method %s of interface %s is not adaptive method!
- url == null
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/2375e7485ac8eda5.
Report an issue: GitHub.