stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown argument " + args[argIndex]

Error message

Unknown argument " + args[argIndex]

What it means

ParseAndSetLabels.main parses command-line flags manually; any argument not matching a known flag (-output, -sentences, -labels, -parser, -tagger, -binarize, etc.) hits the else branch and throws IllegalArgumentException with the offending token. The library fails fast rather than ignoring unknown options.

Solutions

  1. Correct or remove the unknown argument named in the message
  2. List the tool's accepted flags from its source (the argIndex loop in main) and match exactly, case-insensitively
  3. Quote arguments containing spaces so they parse as a single token
  4. Check the flag names against the CoreNLP version you are actually running

Example fix

// before
// java edu.stanford.nlp.parser.tools.ParseAndSetLabels -outpu out.txt ...
// after
// java edu.stanford.nlp.parser.tools.ParseAndSetLabels -output out.txt ...
Defensive patterns

Strategy: validation

Validate before calling

java.util.Set<String> known = java.util.Set.of("-output","-sentences","-labels","-parser","-tagger","-binarize","-useLabelKeys","-nouseLabelKeys","-missingLabelsOptions");
for (String a : args) if (a.startsWith("-") && !known.contains(a.toLowerCase())) throw new IllegalArgumentException("unknown flag: " + a);

Try / catch

try {
  ParseAndSetLabels.main(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unknown argument")) {
    System.err.println("Bad flag: " + e.getMessage() + " — check tool docs for accepted flags");
  }
  throw e;
}

Prevention

When it happens

Trigger: Running the tool's main with a misspelled or unsupported flag, e.g. "java ParseAndSetLabels -outpu file" or an extra positional argument left on the command line.

Common situations: Typos in shell scripts; flags copied from a different Stanford tool that uses different option names; quoting mistakes that leave stray tokens in args; older/newer tool versions with different flag sets.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:235

        saveUnknownsFile = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-remapLabels")) {
        remapLabels = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-binarize")) {
        binarize = true;
        argIndex += 1;
      } else if (args[argIndex].equalsIgnoreCase("-nobinarize")) {
        binarize = false;
        argIndex += 1;
      } else if (args[argIndex].equalsIgnoreCase("-useLabelKeys")) {
        useLabelKeys = true;
        argIndex += 1;
      } else if (args[argIndex].equalsIgnoreCase("-nouseLabelKeys")) {
        useLabelKeys = false;
        argIndex += 1;
      } else {
        throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
      }
    }

    if (outputFile == null) {
      throw new IllegalArgumentException("-output is required");
    }
    if (sentencesFile == null && !useLabelKeys) {
      throw new IllegalArgumentException("-sentences or -useLabelKeys is required");
    }
    if (sentencesFile != null && useLabelKeys) {
      throw new IllegalArgumentException("Use only one of -sentences or -useLabelKeys");
    }
    if (labelsFile == null) {
      throw new IllegalArgumentException("-labels is required");
    }

    ParserGrammar parser = loadParser(parserFile, taggerFile);

View on GitHub (pinned to 1b7edd19c4)