stanfordnlp/CoreNLP · error · RuntimeException

Error: -train option must have treebankPath as first…

Error message

Error: -train option must have treebankPath as first argument.

What it means

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.').

Solutions

  1. Provide the treebank directory path immediately after -train (e.g., -train /path/to/treebank).
  2. Check shell quoting/variable expansion so the path is actually passed as an argument.
  3. If also providing range/filter arguments, keep the path first: -train <treebankPath> [fileRange] [low high start].

Example fix

// before
java ... TreeAnnotatorAndBinarizer -train -maxLength 40
// after
java ... TreeAnnotatorAndBinarizer -train /data/treebank -maxLength 40
Defensive patterns

Strategy: validation

Validate before calling

int i = ArrayUtils.indexOf(args, "-train");
if (i >= 0 && (i + 1 >= args.length || args[i+1].startsWith("-")))
  throw new IllegalArgumentException("-train requires a treebankPath argument");

Try / catch

try {
  TreeAnnotatorAndBinarizer.main(args);
} catch (RuntimeException e) {
  if (e.getMessage().contains("-train option must have treebankPath")) {
    System.err.println("Usage: ... -train <treebankPath> [range] [low high start]");
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Command-line construction bugs in training scripts, quoting mistakes that swallow the path argument, or forgetting the directory path when configuring a training run.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/90f30a44f0d0346f. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/TreeAnnotatorAndBinarizer.java:330

   *
   *  @param args Command line arguments: All flags accepted by FactoredParser.setOptionFlag
   *     and -train treebankPath [fileRanges]
   */
  public static void main(String[] args) {
    Options op = new Options();
    String treebankPath = null;
    FileFilter trainFilter = null;

    int i = 0;
    while (i < args.length && args[i].startsWith("-")) {
      if (args[i].equalsIgnoreCase("-train")) {
        int numSubArgs = numSubArgs(args, i);
        i++;
        if (numSubArgs >= 1) {
          treebankPath = args[i];
          i++;
        } else {
          throw new RuntimeException("Error: -train option must have treebankPath as first argument.");
        }
        if (numSubArgs == 2) {
          trainFilter = new NumberRangesFileFilter(args[i++], true);
        } else if (numSubArgs >= 3) {
          int low = Integer.parseInt(args[i]);
          int high = Integer.parseInt(args[i + 1]);
          trainFilter = new NumberRangeFileFilter(low, high, true);
          i += 2;
        }
      } else {
        i = op.setOption(args, i);
      }
    }
    if (i < args.length) {
      log.info("usage: java TreeAnnotatorAndBinarizer options*");
      log.info("  Options are like for lexicalized parser including -train treebankPath fileRange]");
      return;
    }

View on GitHub (pinned to 1b7edd19c4)