{"record":{"id":"5cc93b26ef9cf5d2","repo":"stanfordnlp/CoreNLP","slug":"labels-is-required","errorCode":null,"errorMessage":"-labels is required","messagePattern":"-labels is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":249,"sourceCode":"      } 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\n    TreeBinarizer binarizer = null;\n    if (binarize) {\n      binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack());\n    }\n\n    Map<String, String> labelMap = readLabelMap(labelsFile, separator, remapLabels);\n\n    List<String> sentences;\n    if (sentencesFile != null) {\n      sentences = readSentences(sentencesFile);\n    } else {\n      sentences = new ArrayList<String>(labelMap.keySet());\n    }\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L231-L267","documentation":"The label map is central to the tool, so main validates that -labels <file> was provided and throws IllegalArgumentException(\"-labels is required\") otherwise. Without a labels file there is no text->label mapping to apply to the trees.","triggerScenarios":"Running ParseAndSetLabels.main without the -labels flag (or with a misspelled variant that never set labelsFile).","commonSituations":"Forgotten flag in scheduled jobs; labels file argument dropped during script refactoring; typo such as -label instead of -labels that hits the unknown-argument branch instead.","solutions":["Add -labels <file> pointing to a TSV mapping of text to label","Verify the flag spelling is -labels (plural)","Ensure the labels file path itself is correct so a subsequent read doesn't fail"],"exampleFix":"// before\n// java ParseAndSetLabels -parser m.gz -sentences s.txt -output o.txt\n// after\n// java ParseAndSetLabels -parser m.gz -sentences s.txt -output o.txt -labels labels.txt","handlingStrategy":"validation","validationCode":"java.util.List<String> a = java.util.Arrays.asList(args);\nif (!a.contains(\"-labels\")) throw new IllegalArgumentException(\"-labels is required\");\nelse if (!new java.io.File(a.get(a.indexOf(\"-labels\") + 1)).exists()) throw new IllegalArgumentException(\"labels file missing\");","typeGuard":null,"tryCatchPattern":"try {\n  ParseAndSetLabels.main(args);\n} catch (IllegalArgumentException e) {\n  if (\"-labels is required\".equals(e.getMessage())) System.err.println(\"Add -labels <file> to the command line\");\n  throw e;\n}","preventionTips":["Always include -labels in command templates","Verify the labels file exists before launch","Avoid near-miss spellings like -label"],"tags":["java","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}