{"record":{"id":"e1fe6d65643c9cc8","repo":"stanfordnlp/CoreNLP","slug":"unknown-argument-args-argindex-e1fe6d","errorCode":null,"errorMessage":"Unknown argument \" + args[argIndex]","messagePattern":"Unknown argument \" \\+ args\\[argIndex\\]","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/PrintTagList.java","lineNumber":28,"sourceCode":"/**\n * Loads a LexicalizedParser and tries to get its tag list.\n *\n * @author John Bauer\n */\npublic class PrintTagList  {\n\n  /** A logger for this class */\n  private static Redwood.RedwoodChannels log = Redwood.channels(PrintTagList.class);\n  public static void main(String[] args) {\n    String parserFile = null;\n    for (int argIndex = 0; argIndex < args.length; ) {\n      if (args[argIndex].equalsIgnoreCase(\"-model\")) {\n        parserFile = args[argIndex + 1];\n        argIndex += 2;\n      } else {\n        String error = \"Unknown argument \" + args[argIndex];\n        log.info(error);\n        throw new RuntimeException(error);\n      }\n    }\n    if (parserFile == null) {\n      log.info(\"Must specify a model file with -model\");\n      System.exit(2);\n    }\n\n    LexicalizedParser parser = LexicalizedParser.loadModel(parserFile);\n\n    Set<String> tags = Generics.newTreeSet();\n    for (String tag : parser.tagIndex) {\n      tags.add(parser.treebankLanguagePack().basicCategory(tag));\n    }\n    System.out.println(\"Basic tags: \" + tags.size());\n    for (String tag : tags) {\n      System.out.print(\"  \" + tag);\n    }\n    System.out.println();","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/PrintTagList.java#L10-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\njava PrintTagList -modelfile parserModel.ser.gz\n// after\njava PrintTagList -model parserModel.ser.gz","handlingStrategy":"validation","validationCode":"// validate args before invoking main\nSet<String> allowed = Set.of(\"-model\");\nfor (int i = 0; i < args.length; i++) {\n  if (!allowed.contains(args[i]))\n    throw new IllegalArgumentException(\"Unsupported flag: \" + args[i]);\n  i++; // skip value\n}\nif (args.length == 0 || !List.of(args).contains(\"-model\"))\n  throw new IllegalArgumentException(\"-model is required\");","typeGuard":null,"tryCatchPattern":"try {\n  PrintTagList.main(args);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unknown argument\")) {\n    System.err.println(\"Bad flag: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["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"],"tags":["cli","argument-parsing","java"],"backgroundTag":"invalid-cli-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}