stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid value for -distanceBin:

Error message

Invalid value for -distanceBin: 

What it means

Options.setOptionFlag validates the -distanceBin argument value: only specific bin counts are supported (distance/coarseDistance combinations, e.g., numBins of 4 or 5). Any other value for -distanceBin makes the parser throw IllegalArgumentException('Invalid value for -distanceBin: ...').

Solutions

  1. Use one of the supported values for -distanceBin (check the numBins branches in setOptionFlag; 4 or 5).
  2. Remove the -distanceBin flag to use the default distance binning.
  3. Update your training script/config to match the option values supported by your parser version.

Example fix

// before
java -cp stanford-parser.jar ... -distanceBin 3 ...
// after
java -cp stanford-parser.jar ... -distanceBin 5 ...
Defensive patterns

Strategy: validation

Validate before calling

if (flag.equals("-distanceBin")) {
  int v = Integer.parseInt(value);
  if (v != 4 && v != 5) throw new IllegalArgumentException("distanceBin must be 4 or 5, got " + v);
}

Try / catch

try {
  options.setOptions(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Invalid value for -distanceBin")) {
    args[argsIdx+1] = "5"; // retry with supported value
  }
}

Prevention

When it happens

Trigger: Supplying '-distanceBin' on the command line (or via setOptions) with a numeric value that is not one of the supported bin counts (e.g., -distanceBin 3 or -distanceBin 6).

Common situations: Copying training options from an old config that used a different number of distance bins, or guessing the allowed values without checking the source.

Understand the failure class

Background: "unknown output mode", "invalid value for flag", "expects true/false": fixing invalid flag value errors in CLI tools — this error's family across 24 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/Options.java:313

      if (order >= 0) {
        trainOptions.markovOrder = order;
        trainOptions.markovFactor = true;
      } else {
        trainOptions.markovFactor = false;
      }
      i += 2;
    } else if (args[i].equalsIgnoreCase("-distanceBins") && (i + 1 < args.length)) {
      int numBins = Integer.parseInt(args[i + 1]);
      if (numBins <= 1) {
        distance = false;
      } else if (numBins == 4) {
        distance = true;
        coarseDistance = true;
      } else if (numBins == 5) {
        distance = true;
        coarseDistance = false;
      } else {
        throw new IllegalArgumentException("Invalid value for -distanceBin: " + args[i+1]);
      }
      i += 2;
    } else if (args[i].equalsIgnoreCase("-noStop")) {
      genStop = false;
      i++;
    } else if (args[i].equalsIgnoreCase("-nonDirectional")) {
      directional = false;
      i++;
    } else if (args[i].equalsIgnoreCase("-depWeight") && (i + 1 < args.length)) {
      testOptions.depWeight = Double.parseDouble(args[i + 1]);
      i += 2;
    } else if (args[i].equalsIgnoreCase("-printPCFGkBest") && (i + 1 < args.length)) {
      testOptions.printPCFGkBest = Integer.parseInt(args[i + 1]);
      i += 2;
    } else if (args[i].equalsIgnoreCase("-evalPCFGkBest") && (i + 1 < args.length)) {
      testOptions.evalPCFGkBest = Integer.parseInt(args[i + 1]);
      i += 2;
    } else if (args[i].equalsIgnoreCase("-printFactoredKGood") && (i + 1 < args.length)) {

View on GitHub (pinned to 1b7edd19c4)