stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Need to supply an output filename with -output

Error message

Need to supply an output filename with -output

What it means

CacheParseHypotheses.main requires an output filename via the -output flag and throws IllegalArgumentException when it is null. The tool writes cached parse hypotheses to this file, so it refuses to run without a destination. Like the other checks in main, it fails fast after argument parsing.

Solutions

  1. Add -output /path/to/file.txt (or .gz) to the command line
  2. Check flag spelling: it must be exactly -output
  3. Ensure the output directory exists and is writable

Example fix

// before
java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -treebank treebank
// after
java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -output hypotheses.txt.gz -treebank treebank
Defensive patterns

Strategy: validation

Validate before calling

List<String> args = Arrays.asList(cmdArgs);
if (!args.contains("-output")) {
    throw new IllegalArgumentException("CacheParseHypotheses requires -output <file>");
}

Try / catch

try {
    CacheParseHypotheses.main(args);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("-output")) {
        System.err.println("Usage: add -output /path/to/hypotheses.txt.gz");
    }
}

Prevention

When it happens

Trigger: Invoking CacheParseHypotheses with -model and -treebank but no -output flag, or misspelling the flag (e.g. -out) so the output field remains null.

Common situations: Automation scripts that build the command dynamically and omit the output path; users familiar with tools that default to stdout expecting this tool to do the same.

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/d9a2eda6732a8879. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/dvparser/CacheParseHypotheses.java:236

      if (args[argIndex].equalsIgnoreCase("-treebank")) {
        Pair<String, FileFilter> treebankDescription = ArgUtils.getTreebankDescription(args, argIndex, "-treebank");
        argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;
        treebanks.add(treebankDescription);
        continue;
      }
      if (args[argIndex].equalsIgnoreCase("-numThreads")) {
        numThreads = Integer.parseInt(args[argIndex + 1]);
        argIndex += 2;
        continue;
      }
      throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
    }

    if (parserModel == null) {
      throw new IllegalArgumentException("Need to supply a parser model with -model");
    }
    if (output == null) {
      throw new IllegalArgumentException("Need to supply an output filename with -output");
    }
    if (treebanks.isEmpty()) {
      throw new IllegalArgumentException("Need to supply a treebank with -treebank");
    }

    log.info("Writing output to " + output);
    log.info("Loading parser model " + parserModel);
    log.info("Writing " + dvKBest + " hypothesis trees for each tree");

    LexicalizedParser parser = LexicalizedParser.loadModel(parserModel, "-dvKBest", Integer.toString(dvKBest));
    CacheParseHypotheses cacher = new CacheParseHypotheses(parser);
    TreeTransformer transformer = DVParser.buildTrainTransformer(parser.getOp());
    List<Tree> sentences = new ArrayList<>();
    for (Pair<String, FileFilter> description : treebanks) {
      log.info("Reading trees from " + description.first);
      Treebank treebank = parser.getOp().tlpParams.memoryTreebank();
      treebank.loadPath(description.first, description.second);

View on GitHub (pinned to 1b7edd19c4)