{"record":{"id":"6b514e705b2c4edb","repo":"apache/dubbo","slug":"compilation-failed-class-diagnostics","errorCode":null,"errorMessage":"Compilation failed. class: {}, diagnostics: {}","messagePattern":"Compilation failed\\. class: (.+?), diagnostics: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/JdkCompiler.java","lineNumber":127,"sourceCode":"\n    @Override\n    public Class<?> doCompile(ClassLoader ignored, String name, String sourceCode) throws Throwable {\n        int i = name.lastIndexOf('.');\n        String packageName = i < 0 ? \"\" : name.substring(0, i);\n        String className = i < 0 ? name : name.substring(i + 1);\n        JavaFileObjectImpl javaFileObject = new JavaFileObjectImpl(className, sourceCode);\n        javaFileManager.putFileForInput(\n                StandardLocation.SOURCE_PATH, packageName, className + ClassUtils.JAVA_EXTENSION, javaFileObject);\n        Boolean result = compiler.getTask(\n                        null,\n                        javaFileManager,\n                        diagnosticCollector,\n                        options,\n                        null,\n                        Collections.singletonList(javaFileObject))\n                .call();\n        if (result == null || !result) {\n            throw new IllegalStateException(\n                    \"Compilation failed. class: \" + name + \", diagnostics: \" + diagnosticCollector.getDiagnostics());\n        }\n        return classLoader.loadClass(name);\n    }\n\n    private static final class JavaFileObjectImpl extends SimpleJavaFileObject {\n\n        private final CharSequence source;\n        private ByteArrayOutputStream bytecode;\n\n        public JavaFileObjectImpl(final String baseName, final CharSequence source) {\n            super(ClassUtils.toURI(baseName + ClassUtils.JAVA_EXTENSION), Kind.SOURCE);\n            this.source = source;\n        }\n\n        JavaFileObjectImpl(final String name, final Kind kind) {\n            super(ClassUtils.toURI(name), kind);\n            source = null;","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/JdkCompiler.java#L109-L145","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the diagnostics list in the exception message — each Diagnostic names the file, line, and error.","Fix the specific syntax/type error reported by the compiler.","Ensure all referenced classes are available to the compilation classloader.","Run on a full JDK (not a JRE) so javax.tools.ToolProvider.getSystemJavaCompiler is non-null."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    compiler.doCompile(classLoader, name, source);\n} catch (IllegalStateException e) {\n    // parse diagnostics in e.getMessage(); fix source/classpath\n}","preventionTips":["Inspect the diagnostics list in the exception to find each compiler error.","Ensure all referenced classes are on the compilation classpath.","Run on a full JDK (not a JRE) so the system compiler is available.","Validate generated source for obvious syntax issues before compiling."],"tags":["compiler","jdk","code-generation","spi","diagnostics"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}