stanfordnlp/CoreNLP · error · RuntimeException
Unknown argument " + args[argIndex]
Error message
Unknown argument " + args[argIndex]
What it means
PrintTagList is a small command-line tool for printing tag lists from a parser model. Its main() loops over CLI arguments and throws RuntimeException when it encounters any flag other than the recognized ones (like -model). The thrown message wraps the unrecognized argument verbatim.
Solutions
- Check the printed message for the offending argument and fix the typo or remove the token
- Prefix the model file path with -model (required: the tool exits with code 2 if parserFile is null)
- Run with no arguments or inspect main() source to list supported flags
- Re-check the tool invocation in your script; note log.info also prints the same message before throwing
Example fix
// before java PrintTagList -modelfile parserModel.ser.gz // after java PrintTagList -model parserModel.ser.gz
Defensive patterns
Strategy: validation
Validate before calling
// validate args before invoking main
Set<String> allowed = Set.of("-model");
for (int i = 0; i < args.length; i++) {
if (!allowed.contains(args[i]))
throw new IllegalArgumentException("Unsupported flag: " + args[i]);
i++; // skip value
}
if (args.length == 0 || !List.of(args).contains("-model"))
throw new IllegalArgumentException("-model is required"); Try / catch
try {
PrintTagList.main(args);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unknown argument")) {
System.err.println("Bad flag: " + e.getMessage());
} else throw e;
} Prevention
- Use exact -model flag name
- Never pass bare positional file paths
- Verify flags against the tool's source or --help output
- Quote shell arguments to avoid stray tokens
When it happens
Trigger: Running PrintTagList with an unrecognized command-line flag, e.g. `java edu.stanford.nlp.parser.tools.PrintTagList -modelfile x` (typo) or with a stray positional token such as a filename passed without a flag.
Common situations: Typos in flag names, using flags from a different Stanford tool, passing a model path without the -model prefix, shell quoting issues 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
- Unknown argument:
- Unknown argument " + args[argIndex]
- Unknown argument
- Unknown argument
- Unknown argument
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/e1fe6d65643c9cc8.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/PrintTagList.java:28
/**
* Loads a LexicalizedParser and tries to get its tag list.
*
* @author John Bauer
*/
public class PrintTagList {
/** A logger for this class */
private static Redwood.RedwoodChannels log = Redwood.channels(PrintTagList.class);
public static void main(String[] args) {
String parserFile = null;
for (int argIndex = 0; argIndex < args.length; ) {
if (args[argIndex].equalsIgnoreCase("-model")) {
parserFile = args[argIndex + 1];
argIndex += 2;
} else {
String error = "Unknown argument " + args[argIndex];
log.info(error);
throw new RuntimeException(error);
}
}
if (parserFile == null) {
log.info("Must specify a model file with -model");
System.exit(2);
}
LexicalizedParser parser = LexicalizedParser.loadModel(parserFile);
Set<String> tags = Generics.newTreeSet();
for (String tag : parser.tagIndex) {
tags.add(parser.treebankLanguagePack().basicCategory(tag));
}
System.out.println("Basic tags: " + tags.size());
for (String tag : tags) {
System.out.print(" " + tag);
}
System.out.println();View on GitHub (pinned to 1b7edd19c4)