stanfordnlp/CoreNLP · error · IllegalArgumentException

-sentences or -useLabelKeys is required

Error message

-sentences or -useLabelKeys is required

What it means

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").

Solutions

  1. Add -sentences <file> to supply sentences to parse, or add -useLabelKeys to reuse labels from the input trees
  2. Do not combine -nouseLabelKeys with an absent -sentences
  3. Check the order of flags so a later -nouseLabelKeys doesn't negate an earlier -useLabelKeys

Example fix

// before
// java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt
// after
// java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt -sentences input.txt
Defensive patterns

Strategy: validation

Validate before calling

java.util.List<String> a = java.util.Arrays.asList(args);
boolean hasInput = a.contains("-sentences") || a.contains("-useLabelKeys");
if (!hasInput) throw new IllegalArgumentException("need -sentences or -useLabelKeys");

Try / catch

try {
  ParseAndSetLabels.main(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("-sentences or -useLabelKeys")) System.err.println("Specify exactly one input mode");
  throw e;
}

Prevention

When it happens

Trigger: Running ParseAndSetLabels.main with neither -sentences <file> nor -useLabelKeys on the command line.

Common situations: Assuming a default input mode exists; dropping -useLabelKeys when copying an older example command; accidentally negating with -nouseLabelKeys after setting -sentences.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/b0647ea076f7e3b5. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:243

      } else if (args[argIndex].equalsIgnoreCase("-nobinarize")) {
        binarize = false;
        argIndex += 1;
      } else if (args[argIndex].equalsIgnoreCase("-useLabelKeys")) {
        useLabelKeys = true;
        argIndex += 1;
      } else if (args[argIndex].equalsIgnoreCase("-nouseLabelKeys")) {
        useLabelKeys = false;
        argIndex += 1;
      } else {
        throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
      }
    }

    if (outputFile == null) {
      throw new IllegalArgumentException("-output is required");
    }
    if (sentencesFile == null && !useLabelKeys) {
      throw new IllegalArgumentException("-sentences or -useLabelKeys is required");
    }
    if (sentencesFile != null && useLabelKeys) {
      throw new IllegalArgumentException("Use only one of -sentences or -useLabelKeys");
    }
    if (labelsFile == null) {
      throw new IllegalArgumentException("-labels is required");
    }

    ParserGrammar parser = loadParser(parserFile, taggerFile);

    TreeBinarizer binarizer = null;
    if (binarize) {
      binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack());
    }

    Map<String, String> labelMap = readLabelMap(labelsFile, separator, remapLabels);

    List<String> sentences;

View on GitHub (pinned to 1b7edd19c4)