{"record":{"id":"b0647ea076f7e3b5","repo":"stanfordnlp/CoreNLP","slug":"sentences-or-uselabelkeys-is-required","errorCode":null,"errorMessage":"-sentences or -useLabelKeys is required","messagePattern":"-sentences or -useLabelKeys is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":243,"sourceCode":"      } 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\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;","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L225-L261","documentation":"main requires a source of input trees: either -sentences (raw sentences to parse) or -useLabelKeys (read labels from the trees themselves). If neither is given, it throws IllegalArgumentException(\"-sentences or -useLabelKeys is required\").","triggerScenarios":"Running ParseAndSetLabels.main with neither -sentences <file> nor -useLabelKeys on the command line.","commonSituations":"Assuming a default input mode exists; dropping -useLabelKeys when copying an older example command; accidentally negating with -nouseLabelKeys after setting -sentences.","solutions":["Add -sentences <file> to supply sentences to parse, or add -useLabelKeys to reuse labels from the input trees","Do not combine -nouseLabelKeys with an absent -sentences","Check the order of flags so a later -nouseLabelKeys doesn't negate an earlier -useLabelKeys"],"exampleFix":"// before\n// java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt\n// after\n// java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt -sentences input.txt","handlingStrategy":"validation","validationCode":"java.util.List<String> a = java.util.Arrays.asList(args);\nboolean hasInput = a.contains(\"-sentences\") || a.contains(\"-useLabelKeys\");\nif (!hasInput) throw new IllegalArgumentException(\"need -sentences or -useLabelKeys\");","typeGuard":null,"tryCatchPattern":"try {\n  ParseAndSetLabels.main(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"-sentences or -useLabelKeys\")) System.err.println(\"Specify exactly one input mode\");\n  throw e;\n}","preventionTips":["Decide the input mode up front in scripts","Watch for -nouseLabelKeys negating an earlier flag","Document the required flags in job definitions"],"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"}