{"record":{"id":"d365d3a6cb260912","repo":"apache/dubbo","slug":"the-java-code-not-endswith-code","errorCode":null,"errorMessage":"The java code not endsWith \"}\", code: \n{}\n","messagePattern":"The java code not endsWith \"\\}\", code: \n(.+?)\n","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/AbstractCompiler.java","lineNumber":67,"sourceCode":"        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;\n            } catch (Throwable t) {\n                throw new IllegalStateException(\"Failed to compile class, cause: \" + t.getMessage() + \", class: \"\n                        + className + \", code: \\n\" + code + \"\\n, stack: \" + ClassUtils.toString(t));\n            }\n        } finally {\n            lock.unlock();\n        }\n    }\n\n    protected Class<?> doCompile(ClassLoader classLoader, String name, String source) throws Throwable {\n        return null;\n    }\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/AbstractCompiler.java#L49-L85","documentation":"Thrown by AbstractCompiler.compile when the class was not found via Class.forName and the source code does not end with '}'. This indicates the source string is truncated or malformed; a complete Java compilation unit must end with the closing brace of the class body.","triggerScenarios":"After Class.forName fails, the code checks code.endsWith(\"}\"); if false, it throws immediately rather than attempting to compile an incomplete source. Happens when the generated or supplied source string was cut off.","commonSituations":"A StringBuilder-based code generator that builds the source incrementently forgot the final append of '}'. A size/buffer limit truncated the string. Copy-paste of a code template missed the closing brace.","solutions":["Ensure the source code string ends with '}' after trimming.","Inspect the code generator that assembles the source and confirm it appends the class-closing brace.","Log the full code string to see exactly where it was truncated.","Increase any buffer/length cap that may be cutting the source short."],"exampleFix":"// before\nStringBuilder sb = new StringBuilder();\nsb.append(\"public class Foo {\"); /* forgot closing brace */\n// after\nsb.append(\"public class Foo {\");\nsb.append(\"}\");","handlingStrategy":"validation","validationCode":"String code = sourceCode.trim();\nif (!code.endsWith(\"}\")) {\n    throw new IllegalStateException(\"source is truncated; does not end with '}'\");\n}\ncompiler.compile(neighbor, code, classLoader);","typeGuard":"static boolean isCompleteSource(String code) {\n    return code != null && code.trim().endsWith(\"}\");\n}","tryCatchPattern":"try {\n    compiler.compile(neighbor, code, classLoader);\n} catch (IllegalStateException e) {\n    // source truncated; regenerate with closing brace\n}","preventionTips":["Ensure code generators append the final '}' to the source.","Log the full source string to spot truncation.","Check buffer/length caps that may cut the source short."],"tags":["compiler","code-generation","validation","truncation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}