apache/dubbo · error · IllegalStateException

Compilation failed. class

Error message

Compilation failed. class: {}, diagnostics: {}

What it means

Thrown by JdkCompiler.doCompile when the JSR-199 compilation task returns null or false, indicating the source did not compile. The bundled diagnosticCollector.getDiagnostics() output lists the compiler errors (syntax, unresolved symbols, etc.).

Solutions

  1. Inspect the diagnostics list in the exception message — each Diagnostic names the file, line, and error.
  2. Fix the specific syntax/type error reported by the compiler.
  3. Ensure all referenced classes are available to the compilation classloader.
  4. Run on a full JDK (not a JRE) so javax.tools.ToolProvider.getSystemJavaCompiler is non-null.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    compiler.doCompile(classLoader, name, source);
} catch (IllegalStateException e) {
    // parse diagnostics in e.getMessage(); fix source/classpath
}

Prevention

When it happens

Trigger: The source code passed to JdkCompiler (the default SPI compiler when running on a JDK) contains a syntax error, references an undefined type/member, or violates Java language rules, so the compiler task returns false.

Common situations: Generated Adaptive/SPI extension source is invalid. A class referenced by the generated source is not on the classpath. Running on a JRE (not JDK) where the compiler tool is unavailable can also yield a failed task. Source/target version mismatch with the running JDK.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/6b514e705b2c4edb. Report an issue: GitHub.

Appendix: source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/JdkCompiler.java:127

    @Override
    public Class<?> doCompile(ClassLoader ignored, String name, String sourceCode) throws Throwable {
        int i = name.lastIndexOf('.');
        String packageName = i < 0 ? "" : name.substring(0, i);
        String className = i < 0 ? name : name.substring(i + 1);
        JavaFileObjectImpl javaFileObject = new JavaFileObjectImpl(className, sourceCode);
        javaFileManager.putFileForInput(
                StandardLocation.SOURCE_PATH, packageName, className + ClassUtils.JAVA_EXTENSION, javaFileObject);
        Boolean result = compiler.getTask(
                        null,
                        javaFileManager,
                        diagnosticCollector,
                        options,
                        null,
                        Collections.singletonList(javaFileObject))
                .call();
        if (result == null || !result) {
            throw new IllegalStateException(
                    "Compilation failed. class: " + name + ", diagnostics: " + diagnosticCollector.getDiagnostics());
        }
        return classLoader.loadClass(name);
    }

    private static final class JavaFileObjectImpl extends SimpleJavaFileObject {

        private final CharSequence source;
        private ByteArrayOutputStream bytecode;

        public JavaFileObjectImpl(final String baseName, final CharSequence source) {
            super(ClassUtils.toURI(baseName + ClassUtils.JAVA_EXTENSION), Kind.SOURCE);
            this.source = source;
        }

        JavaFileObjectImpl(final String name, final Kind kind) {
            super(ClassUtils.toURI(name), kind);
            source = null;

View on GitHub (pinned to 3a3043227f)