{"record":{"id":"16a8107d2d8c3aec","repo":"stanfordnlp/CoreNLP","slug":"error-train-option-must-have-treebankpath-as-fir","errorCode":null,"errorMessage":"Error: -train option must have treebankPath as first argument.","messagePattern":"Error: -train option must have treebankPath as first argument\\.","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/ChineseLexiconAndWordSegmenter.java","lineNumber":438,"sourceCode":"                         \"LexicalizedParser parserFileOrUrl filename*\");\n      return;\n    }\n\n    Options op = new Options();\n    op.tlpParams = new ChineseTreebankParserParams();\n\n    // while loop through option arguments\n    while (argIndex < args.length && args[argIndex].charAt(0) == '-') {\n      if (args[argIndex].equalsIgnoreCase(\"-train\")) {\n        train = true;\n        saveToSerializedFile = true;\n        int numSubArgs = numSubArgs(args, argIndex);\n        argIndex++;\n        if (numSubArgs > 1) {\n          treebankPath = args[argIndex];\n          argIndex++;\n        } else {\n          throw new RuntimeException(\"Error: -train option must have treebankPath as first argument.\");\n        }\n        if (numSubArgs == 2) {\n          trainFilter = new NumberRangesFileFilter(args[argIndex++], true);\n        } else if (numSubArgs >= 3) {\n          try {\n            int low = Integer.parseInt(args[argIndex]);\n            int high = Integer.parseInt(args[argIndex + 1]);\n            trainFilter = new NumberRangeFileFilter(low, high, true);\n            argIndex += 2;\n          } catch (NumberFormatException e) {\n            // maybe it's a ranges expression?\n            trainFilter = new NumberRangesFileFilter(args[argIndex], true);\n            argIndex++;\n          }\n        }\n      } else if (args[argIndex].equalsIgnoreCase(\"-encoding\")) { // sets encoding for TreebankLangParserParams\n        encoding = args[argIndex + 1];\n        op.tlpParams.setInputEncoding(encoding);","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ChineseLexiconAndWordSegmenter.java#L420-L456","documentation":"The -train option of ChineseLexiconAndWordSegmenter.main requires at least two sub-arguments, with the treebank path as the first one. If only one (or zero) sub-arguments follow -train, the option parser throws RuntimeException because it cannot determine where the training treebank lives.","triggerScenarios":"Running the segmenter's main() with a -train flag that lists fewer than 2 arguments, e.g. -train only a file path with no second argument, when the code requires numSubArgs > 1 to read treebankPath.","commonSituations":"Command-line invocations of the Chinese parser trainer missing the second argument (e.g. tree range/filter parameters), copy-pasted command lines where a filter argument was dropped, or scripting errors.","solutions":["Provide the treebank path as the first argument after -train plus at least one more argument, e.g. -train /path/to/treebank 100-9999","Verify the command line includes the expected number of sub-arguments (the parser reads numSubArgs(args, argIndex) from the value preceding them)","Consult the usage documentation for -train's expected argument format"],"exampleFix":"// before\njava ... -train /path/to/chineseTreebank\n// after\njava ... -train /path/to/chineseTreebank 100-9999","handlingStrategy":"validation","validationCode":"if (args contains \"-train\") { String[] sub = nextArgs(args, idx); if (sub.length < 2) throw new IllegalArgumentException(\"-train needs treebankPath plus filter args\"); }","typeGuard":null,"tryCatchPattern":"try { ChineseLexiconAndWordSegmenter.main(args); } catch (RuntimeException e) { if (e.getMessage().contains(\"-train option\")) printUsage(); }","preventionTips":["Always pass treebankPath as the first -train sub-argument","Build command lines programmatically and validate arg counts before invoking main"],"tags":["java","parser","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}