stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown argument:

Error message

Unknown argument: 

What it means

AddTaggerToParser.main parses its command-line arguments with a hand-rolled loop that throws IllegalArgumentException for any flag it does not recognize. The message concatenates the offending token so the user can see which argument was rejected.

Solutions

  1. Use only the supported flags (e.g. -input, -output, -weight); check the source for exact names
  2. Fix the misspelled flag name in the command line
  3. Remove arguments intended for other tools

Example fix

// before
java AddTaggerToParser -model parser.ser.gz -tagger tagger.ser.gz -output out.ser.gz
// after
java AddTaggerToParser -input parser.ser.gz -taggerFile tagger.ser.gz -output out.ser.gz
Defensive patterns

Strategy: validation

Validate before calling

// validate flags before invoking
Set<String> allowed = Set.of("-input", "-output", "-weight");
for (int i = 0; i < args.length; i += 2) {
  if (!allowed.contains(args[i].toLowerCase())) {
    throw new IllegalArgumentException("Unsupported flag for AddTaggerToParser: " + args[i]);
  }
}

Try / catch

try {
  AddTaggerToParser.main(args);
} catch (IllegalArgumentException e) {
  System.err.println("Bad flag: " + e.getMessage() + " — allowed: -input, -output, -weight");
  System.exit(2);
}

Prevention

When it happens

Trigger: Invoking the tool with a flag other than the supported ones (e.g. -input, -output, -weight variants misspelled, or flags copied from other LexicalizedParser tools such as -model or -taggerFile that this tool does not implement).

Common situations: Copy-pasting option lists between Stanford parser tools; typo like '-inputFile' instead of the exact supported flag; quoting mistakes leaving stray tokens in args.

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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/AddTaggerToParser.java:33

    String outputFile = null;

    double weight = 1.0;
    
    for (int argIndex = 0; argIndex < args.length; ) {
      if (args[argIndex].equalsIgnoreCase("-tagger")) {
        taggerFile = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-input")) {
        inputFile = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-output")) {
        outputFile = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-weight")) {
        weight = Double.valueOf(args[argIndex + 1]);
        argIndex += 2;
      } else {
        throw new IllegalArgumentException("Unknown argument: " + args[argIndex]);
      }
    }

    LexicalizedParser parser = LexicalizedParser.loadModel(inputFile);
    MaxentTagger tagger = new MaxentTagger(taggerFile);
    parser.reranker = new TaggerReranker(tagger, parser.getOp());
    parser.saveParserToSerialized(outputFile);
  }
}

View on GitHub (pinned to 1b7edd19c4)