{"record":{"id":"dafbfec8dc8879e7","repo":"stanfordnlp/CoreNLP","slug":"unknown-argument-args-argindex-dafbfe","errorCode":null,"errorMessage":"Unknown argument \" + args[argIndex]","messagePattern":"Unknown argument \" \\+ args\\[argIndex\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":235,"sourceCode":"        saveUnknownsFile = args[argIndex + 1];\n        argIndex += 2;\n      } else if (args[argIndex].equalsIgnoreCase(\"-remapLabels\")) {\n        remapLabels = args[argIndex + 1];\n        argIndex += 2;\n      } else if (args[argIndex].equalsIgnoreCase(\"-binarize\")) {\n        binarize = true;\n        argIndex += 1;\n      } else if (args[argIndex].equalsIgnoreCase(\"-nobinarize\")) {\n        binarize = false;\n        argIndex += 1;\n      } else if (args[argIndex].equalsIgnoreCase(\"-useLabelKeys\")) {\n        useLabelKeys = true;\n        argIndex += 1;\n      } else if (args[argIndex].equalsIgnoreCase(\"-nouseLabelKeys\")) {\n        useLabelKeys = false;\n        argIndex += 1;\n      } else {\n        throw new IllegalArgumentException(\"Unknown argument \" + args[argIndex]);\n      }\n    }\n\n    if (outputFile == null) {\n      throw new IllegalArgumentException(\"-output is required\");\n    }\n    if (sentencesFile == null && !useLabelKeys) {\n      throw new IllegalArgumentException(\"-sentences or -useLabelKeys is required\");\n    }\n    if (sentencesFile != null && useLabelKeys) {\n      throw new IllegalArgumentException(\"Use only one of -sentences or -useLabelKeys\");\n    }\n    if (labelsFile == null) {\n      throw new IllegalArgumentException(\"-labels is required\");\n    }\n\n    ParserGrammar parser = loadParser(parserFile, taggerFile);\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L217-L253","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Correct or remove the unknown argument named in the message","List the tool's accepted flags from its source (the argIndex loop in main) and match exactly, case-insensitively","Quote arguments containing spaces so they parse as a single token","Check the flag names against the CoreNLP version you are actually running"],"exampleFix":"// before\n// java edu.stanford.nlp.parser.tools.ParseAndSetLabels -outpu out.txt ...\n// after\n// java edu.stanford.nlp.parser.tools.ParseAndSetLabels -output out.txt ...","handlingStrategy":"validation","validationCode":"java.util.Set<String> known = java.util.Set.of(\"-output\",\"-sentences\",\"-labels\",\"-parser\",\"-tagger\",\"-binarize\",\"-useLabelKeys\",\"-nouseLabelKeys\",\"-missingLabelsOptions\");\nfor (String a : args) if (a.startsWith(\"-\") && !known.contains(a.toLowerCase())) throw new IllegalArgumentException(\"unknown flag: \" + a);","typeGuard":null,"tryCatchPattern":"try {\n  ParseAndSetLabels.main(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unknown argument\")) {\n    System.err.println(\"Bad flag: \" + e.getMessage() + \" — check tool docs for accepted flags\");\n  }\n  throw e;\n}","preventionTips":["Copy flags from the tool's source/docs, not other Stanford tools","Quote args with spaces","Pin the CoreNLP version your scripts were written for"],"tags":["java","cli","argument-parsing"],"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"}