{"record":{"id":"90f30a44f0d0346f","repo":"stanfordnlp/CoreNLP","slug":"error-train-option-must-have-treebankpath-as-fir-90f30a","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/TreeAnnotatorAndBinarizer.java","lineNumber":330,"sourceCode":"   *\n   *  @param args Command line arguments: All flags accepted by FactoredParser.setOptionFlag\n   *     and -train treebankPath [fileRanges]\n   */\n  public static void main(String[] args) {\n    Options op = new Options();\n    String treebankPath = null;\n    FileFilter trainFilter = null;\n\n    int i = 0;\n    while (i < args.length && args[i].startsWith(\"-\")) {\n      if (args[i].equalsIgnoreCase(\"-train\")) {\n        int numSubArgs = numSubArgs(args, i);\n        i++;\n        if (numSubArgs >= 1) {\n          treebankPath = args[i];\n          i++;\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[i++], true);\n        } else if (numSubArgs >= 3) {\n          int low = Integer.parseInt(args[i]);\n          int high = Integer.parseInt(args[i + 1]);\n          trainFilter = new NumberRangeFileFilter(low, high, true);\n          i += 2;\n        }\n      } else {\n        i = op.setOption(args, i);\n      }\n    }\n    if (i < args.length) {\n      log.info(\"usage: java TreeAnnotatorAndBinarizer options*\");\n      log.info(\"  Options are like for lexicalized parser including -train treebankPath fileRange]\");\n      return;\n    }","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/TreeAnnotatorAndBinarizer.java#L312-L348","documentation":"TreeAnnotatorAndBinarizer's main() parses the -train option by consuming its sub-arguments; the first sub-argument must be the treebank path. If -train is given with no sub-arguments, it throws RuntimeException('Error: -train option must have treebankPath as first argument.').","triggerScenarios":"Running the tool with '-train' as the last argument, or '-train' followed immediately by another flag so numSubArgs(args, i) is 0 and no treebankPath is available.","commonSituations":"Command-line construction bugs in training scripts, quoting mistakes that swallow the path argument, or forgetting the directory path when configuring a training run.","solutions":["Provide the treebank directory path immediately after -train (e.g., -train /path/to/treebank).","Check shell quoting/variable expansion so the path is actually passed as an argument.","If also providing range/filter arguments, keep the path first: -train <treebankPath> [fileRange] [low high start]."],"exampleFix":"// before\njava ... TreeAnnotatorAndBinarizer -train -maxLength 40\n// after\njava ... TreeAnnotatorAndBinarizer -train /data/treebank -maxLength 40","handlingStrategy":"validation","validationCode":"int i = ArrayUtils.indexOf(args, \"-train\");\nif (i >= 0 && (i + 1 >= args.length || args[i+1].startsWith(\"-\")))\n  throw new IllegalArgumentException(\"-train requires a treebankPath argument\");","typeGuard":null,"tryCatchPattern":"try {\n  TreeAnnotatorAndBinarizer.main(args);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"-train option must have treebankPath\")) {\n    System.err.println(\"Usage: ... -train <treebankPath> [range] [low high start]\");\n  }\n}","preventionTips":["Always place the treebank directory right after -train.","Quote paths with spaces in shell scripts.","Test training command lines with an argument-echo before the real run."],"tags":["cli","training","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"}