stanfordnlp/CoreNLP · error · IllegalArgumentException

Need to specify -output

Error message

Need to specify -output

What it means

FindNearestNeighbors writes its nearest-neighbor results to a file given by -output. main() throws this IllegalArgumentException when outputPath is null. It is the last of the three mandatory option checks before any processing.

Solutions

  1. Add -output <path-to-result-file> to the command
  2. Ensure the directory for the output path exists and is writable
  3. Supply all three flags: -model, -testTreebank, -output

Example fix

// before
FindNearestNeighbors -model dvparser.ser.gz -testTreebank test.gold
// after
FindNearestNeighbors -model dvparser.ser.gz -testTreebank test.gold -output neighbors.txt
Defensive patterns

Strategy: validation

Validate before calling

if (!Arrays.asList(args).contains("-output")) {
  throw new IllegalArgumentException("FindNearestNeighbors requires -output <file>");
}

Try / catch

try {
  FindNearestNeighbors.main(args);
} catch (IllegalArgumentException e) {
  System.err.println("Missing required option: " + e.getMessage());
}

Prevention

When it happens

Trigger: Running FindNearestNeighbors.main() with -model and -testTreebank but without -output.

Common situations: Redirecting stdout instead of using -output; forgetting the flag in batch scripts; confusing this tool's output flag with DVParser's -model output naming.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/dvparser/FindNearestNeighbors.java:94

        argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;
        testTreebankPath = treebankDescription.first();
        testTreebankFilter = treebankDescription.second();
      } else if (args[argIndex].equalsIgnoreCase("-output")) {
        outputPath = args[argIndex + 1];
        argIndex += 2;
      } else {
        unusedArgs.add(args[argIndex++]);
      }
    }

    if (modelPath == null) {
      throw new IllegalArgumentException("Need to specify -model");
    }
    if (testTreebankPath == null) {
      throw new IllegalArgumentException("Need to specify -testTreebank");
    }
    if (outputPath == null) {
      throw new IllegalArgumentException("Need to specify -output");
    }

    String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);

    LexicalizedParser lexparser = LexicalizedParser.loadModel(modelPath, newArgs);

    Treebank testTreebank = null;
    if (testTreebankPath != null) {
      log.info("Reading in trees from " + testTreebankPath);
      if (testTreebankFilter != null) {
        log.info("Filtering on " + testTreebankFilter);
      }
      testTreebank = lexparser.getOp().tlpParams.memoryTreebank();;
      testTreebank.loadPath(testTreebankPath, testTreebankFilter);
      log.info("Read in " + testTreebank.size() + " trees for testing");
    }

    FileWriter out = new FileWriter(outputPath);

View on GitHub (pinned to 1b7edd19c4)