stanfordnlp/CoreNLP · error · IllegalArgumentException

-o argument (output path for built tagger) is required

Error message

-o argument (output path for built tagger) is required

What it means

AnCoraPOSStats is a command-line tool that builds a Spanish POS tagger from AnCora corpus files. It parses CLI options via StringUtils.argsToProperties and requires the '-o' flag to know where to write the resulting tagger model. If '-o' is absent it throws this IllegalArgumentException immediately after option parsing.

Solutions

  1. Add the required flag: pass -o /path/to/output.tagger when running AnCoraPOSStats.
  2. Check for typos in the flag (single dash, single letter 'o').
  3. If invoking programmatically, include "-o" and its value in the args array.
  4. Wrap the call in a catch for IllegalArgumentException to surface a friendly usage message if you control the launcher.

Example fix

// before
java edu.stanford.nlp.international.spanish.pipeline.AnCoraPOSStats -t -f trainFiles.txt
// after
java edu.stanford.nlp.international.spanish.pipeline.AnCoraPOSStats -o /models/ancora.tagger -t -f trainFiles.txt
Defensive patterns

Strategy: validation

Validate before calling

// before calling main(args)
Properties opts = StringUtils.argsToProperties(args);
if (opts.getProperty("o") == null)
  throw new IllegalArgumentException("Usage: AnCoraPOSStats -o <outputPath> [corpus files...]");

Try / catch

try {
  AnCoraPOSStats.main(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("-o argument")) {
    System.err.println("Missing required -o flag. Usage: AnCoraPOSStats -o <outputPath> ...");
    System.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the AnCoraPOSStats main method without the '-o' flag, or passing options misspelled so they are not recognized (e.g. '--output' or '-output' instead of '-o'), so options.getProperty("o") returns null.

Common situations: Invocation scripts or README commands copied without the output flag; shell wrappers that drop empty-string args; users assuming a default output path exists; calling main() programmatically from tests or other code with an args array lacking '-o'.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/spanish/pipeline/AnCoraPOSStats.java:89

  private static final String usage =
    String.format("Usage: java %s -o <output_path> file(s)%n%n", AnCoraPOSStats.class.getName());

  private static final Map<String, Integer> argOptionDefs = new HashMap<>();
  static {
    argOptionDefs.put("o", 1);
  }

  public static void main(String[] args) throws IOException {
    if (args.length < 1) {
      log.info(usage);
      System.exit(1);
    }

    Properties options = StringUtils.argsToProperties(args, argOptionDefs);

    String outputPath = options.getProperty("o");
    if (outputPath == null)
      throw new IllegalArgumentException("-o argument (output path for built tagger) is required");

    String[] remainingArgs = options.getProperty("").split(" ");
    List<File> fileList = new ArrayList<>();
    for (String arg : remainingArgs)
      fileList.add(new File(arg));

    AnCoraPOSStats stats = new AnCoraPOSStats(fileList, outputPath);
    stats.process();

    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(outputPath));
    TwoDimensionalCounter<String, String> tagger = stats.getUnigramTagger();
    oos.writeObject(tagger);

    System.out.printf("Wrote tagger to %s%n", outputPath);
  }

}

View on GitHub (pinned to 1b7edd19c4)