stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown argument " + newArgs[argIndex]

Error message

Unknown argument " + newArgs[argIndex]

What it means

Evaluate.main loads a serialized SentimentModel then feeds remaining args to model.op.setOption; if setOption consumes nothing (argIndex unchanged), the argument is unrecognized and it throws IllegalArgumentException after logging it. It guards against silently ignoring mistyped options.

Solutions

  1. Fix or remove the unrecognized flag reported in the log message
  2. Check RNNOptions.setOption for the exact supported option names
  3. Verify you are running the intended sentiment entry point (Evaluate vs other mains) for your flags

Example fix

// before
java Evaluate -model model.ser.gz -treepath trees.txt -modle ...
// after
java Evaluate -model model.ser.gz -treepath trees.txt
Defensive patterns

Strategy: try-catch

Validate before calling

for (String a : args) {
  if (a.startsWith("-") && !KNOWN_FLAGS.contains(a)) throw new IllegalArgumentException("Unknown flag: " + a);
}

Try / catch

try {
  Evaluate.main(args);
} catch (IllegalArgumentException e) {
  log.error("Bad Evaluate option: " + e.getMessage());
}

Prevention

When it happens

Trigger: Running Evaluate with any flag not understood by RNNOptions.setOption, e.g. a typo like -modle, or an option that belongs to a different sentiment tool.

Common situations: Copying command lines from tutorials for a different class; renamed/removed options across CoreNLP versions; quoting mistakes producing stray tokens in args.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/sentiment/Evaluate.java:144

      } else if (args[argIndex].equalsIgnoreCase("-treebank")) {
        treePath = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-filterUnknown")) {
        filterUnknown = true;
        argIndex++;
      } else {
        remainingArgs.add(args[argIndex]);
        argIndex++;
      }
    }
    String[] newArgs = new String[remainingArgs.size()];
    remainingArgs.toArray(newArgs);
    SentimentModel model = SentimentModel.loadSerialized(modelPath);
    for (int argIndex = 0; argIndex < newArgs.length;) {
      int newIndex = model.op.setOption(newArgs, argIndex);
      if (argIndex == newIndex) {
        log.info("Unknown argument " + newArgs[argIndex]);
        throw new IllegalArgumentException("Unknown argument " + newArgs[argIndex]);
      }
      argIndex = newIndex;
    }
    List<Tree> trees = SentimentUtils.readTreesWithGoldLabels(treePath);
    if (filterUnknown) {
      trees = SentimentUtils.filterUnknownRoots(trees);
    }
    Evaluate eval = new Evaluate(model);
    eval.eval(trees);
    eval.printSummary();
  }

}

View on GitHub (pinned to 1b7edd19c4)