{"record":{"id":"13d7954d1a74dc22","repo":"hankcs/HanLP","slug":"conversion-failed-with-code-code-for-src-the","errorCode":null,"errorMessage":"Conversion failed with code {code} for {src}. The err message is:\\n {err}\\nDo you have java installed? Do you have enough memory?","messagePattern":"Conversion failed with code (.+?) for (.+?)\\. The err message is:\\\\n (.+?)\\\\nDo you have java installed\\? Do you have enough memory\\?","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"hanlp/datasets/parsing/loaders/_ctb_utils.py","lineNumber":103,"sourceCode":"    sp_home = get_resource(sp_home)\n    # jar_path = get_resource(f'{sp_home}#stanford-parser.jar')\n    if ud:\n        jclass = 'edu.stanford.nlp.trees.international.pennchinese.UniversalChineseGrammaticalStructure' if language == 'zh' \\\n            else 'edu.stanford.nlp.trees.ud.UniversalDependenciesConverter'\n    else:\n        jclass = 'edu.stanford.nlp.trees.international.pennchinese.ChineseGrammaticalStructure' if language == 'zh' \\\n            else 'edu.stanford.nlp.trees.EnglishGrammaticalStructure'\n    cmd = f'java -cp {sp_home}/* {jclass} ' \\\n          f'-treeFile {src}'\n    if conllx:\n        cmd += ' -conllx'\n    if not ud:\n        cmd += f' -basic -keepPunct'\n    code, out, err = get_exitcode_stdout_stderr(cmd)\n    with open(dst, 'w') as f:\n        f.write(out)\n    if code:\n        raise RuntimeError(f'Conversion failed with code {code} for {src}. The err message is:\\n {err}\\n'\n                           f'Do you have java installed? Do you have enough memory?')\n\n\ndef clean_ctb_bracketed(ctb_root, out_root):\n    os.makedirs(out_root, exist_ok=True)\n    ctb_root = join(ctb_root, 'bracketed')\n    chtbs = _list_treebank_root(ctb_root)\n    timer = CountdownTimer(len(chtbs))\n    for f in chtbs:\n        with open(join(ctb_root, f), encoding='utf-8') as src, open(join(out_root, f + '.txt'), 'w',\n                                                                    encoding='utf-8') as out:\n            for line in src:\n                if not line.strip().startswith('<'):\n                    out.write(line)\n        timer.log('Cleaning up CTB [blink][yellow]...[/yellow][/blink]', erase=False)\n\n\ndef _list_treebank_root(ctb_root):","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/datasets/parsing/loaders/_ctb_utils.py#L85-L121","documentation":"After running the Stanford Parser jar via subprocess to convert CTB trees, convert_to_dependency checks the process exit code. A non-zero code means java failed (missing JVM, wrong java version, or out-of-memory during conversion), and the collected stderr is included in the RuntimeError.","triggerScenarios":"Running make_ctb_tasks/make_dep_conllx on a machine without java on PATH; java too old/new for the Stanford Parser jar; large treebank conversions exhausting heap (default JVM max heap).","commonSituations":"Fresh CI containers or slim Docker images without a JDK; converting full CTB9 where the parser needs several GB of heap.","solutions":["Install a JDK/JRE (java -version must work) — Stanford Parser 4.2.0 needs Java 8+","If it's an OOM, raise heap: export JAVA_OPTS or _JAVA_OPTIONS='-Xmx8g' and retry","Check the err text in the message for the underlying java error and address it (version mismatch, corrupt download)","Verify the Stanford Parser zip downloaded fully (re-download if corrupted)"],"exampleFix":"# shell\nsudo apt-get install -y openjdk-11-jre-headless\nexport _JAVA_OPTIONS='-Xmx8g'\npython prepare_ctb.py","handlingStrategy":"try-catch","validationCode":"import shutil\nif shutil.which('java') is None:\n    raise SystemExit('java not found; install a JDK/JRE before conversion')","typeGuard":null,"tryCatchPattern":"try:\n    convert_to_dependency(src, dst, language='zh', version='4.2.0')\nexcept RuntimeError as e:\n    msg = str(e)\n    if 'enough memory' in msg:\n        import os\n        os.environ['_JAVA_OPTIONS'] = '-Xmx8g'\n        convert_to_dependency(src, dst, language='zh', version='4.2.0')\n    else:\n        raise","preventionTips":["Pre-check `which java` and set -Xmx heap before batch conversions","Run a small smoke conversion on one file before processing the full treebank"],"tags":["python","java","subprocess","stanford-parser","out-of-memory"],"backgroundTag":"subprocess-exit-nonzero","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}