{"record":{"id":"babf823afdc3976a","repo":"apache/dubbo","slug":"no-such-class-name-in","errorCode":null,"errorMessage":"No such class name in {}","messagePattern":"No such class name in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/AbstractCompiler.java","lineNumber":54,"sourceCode":"\n    private static final Map<String, Lock> CLASS_IN_CREATION_MAP = new ConcurrentHashMap<>();\n\n    @Override\n    public Class<?> compile(Class<?> neighbor, String code, ClassLoader classLoader) {\n        code = code.trim();\n        Matcher matcher = PACKAGE_PATTERN.matcher(code);\n        String pkg;\n        if (matcher.find()) {\n            pkg = matcher.group(1);\n        } else {\n            pkg = \"\";\n        }\n        matcher = CLASS_PATTERN.matcher(code);\n        String cls;\n        if (matcher.find()) {\n            cls = matcher.group(1);\n        } else {\n            throw new IllegalArgumentException(\"No such class name in \" + code);\n        }\n        String className = pkg != null && pkg.length() > 0 ? pkg + \".\" + cls : cls;\n        Lock lock = CLASS_IN_CREATION_MAP.get(className);\n        if (lock == null) {\n            CLASS_IN_CREATION_MAP.putIfAbsent(className, new ReentrantLock());\n            lock = CLASS_IN_CREATION_MAP.get(className);\n        }\n        try {\n            lock.lock();\n            return Class.forName(className, true, classLoader);\n        } catch (ClassNotFoundException e) {\n            if (!code.endsWith(\"}\")) {\n                throw new IllegalStateException(\"The java code not endsWith \\\"}\\\", code: \\n\" + code + \"\\n\");\n            }\n            try {\n                return doCompile(neighbor, classLoader, className, code);\n            } catch (RuntimeException t) {\n                throw t;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/AbstractCompiler.java#L36-L72","documentation":"Thrown by AbstractCompiler.compile when the source code string does not contain a class declaration matching the CLASS_PATTERN regex ('class <Name>'). The compiler needs a class name to compile against, so a source without one is rejected as invalid input.","triggerScenarios":"Calling compiler.compile(neighbor, code, classLoader) with a code string that has no 'class Xxx ' token — e.g. a code fragment, an interface/enum without the 'class' keyword positioned as expected, or a malformed/truncated snippet.","commonSituations":"Dynamic compilation of a SPI implementation (e.g. Adaptive extensions generated by Dubbo) where the generated source is malformed. A custom Compiler user passing a snippet that is not a full class. Truncation of the source string during generation.","solutions":["Ensure the source code contains a 'class <Name> {' declaration that the CLASS_PATTERN regex can match.","If compiling an interface or enum, verify the regex expectations — the pattern specifically looks for 'class '.","Log the full code string before calling compile to inspect what is actually being passed.","Check the code generator (e.g. AdaptiveExtensionInjector codegen) that produced the source for bugs."],"exampleFix":"// before\nString code = \"public void doSomething() {}\";  // no class decl\n// after\nString code = \"public class Foo { public void doSomething() {} }\";","handlingStrategy":"validation","validationCode":"String code = sourceCode.trim();\nif (!code.matches(\"(?s).*\\\\bclass\\\\s+[$_a-zA-Z][$_a-zA-Z0-9]*\\\\b.*\")) {\n    throw new IllegalArgumentException(\"source has no class declaration\");\n}\ncompiler.compile(neighbor, code, classLoader);","typeGuard":"static boolean hasClassDeclaration(String code) {\n    return code != null && java.util.regex.Pattern.compile(\n        \"class\\\\s+([$_a-zA-Z][$_a-zA-Z0-9]*)\\\\s+\").matcher(code).find();\n}","tryCatchPattern":"try {\n    compiler.compile(neighbor, code, classLoader);\n} catch (IllegalArgumentException e) {\n    // no class name found; inspect and fix the source string\n}","preventionTips":["Validate the source contains a 'class <Name> {' declaration before compiling.","Log the full generated source when compilation fails.","Test SPI/Adaptive code generators to ensure they emit valid class declarations."],"tags":["compiler","code-generation","validation","spi"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}