stanfordnlp/CoreNLP · error · IllegalArgumentException

Right order must be non-negative, not

Error message

Right order must be non-negative, not ${rightOrder}

What it means

The order(l,r) feature spec in ExtractorFrames allows negative left orders but requires the right order to be non-negative, since right-order features look forward k positions. A negative rightOrder value throws this IllegalArgumentException during extractor-frame parsing.

Solutions

  1. Make the right order non-negative, e.g. use order(-2,1) instead of order(-2,-1)
  2. Remember left order may be negative (tags to the left) but right order counts tags to the right and must be >= 0
  3. If you only want left context, use order(-3,0)
  4. Double-check the argument order: first number is left (may be negated), second is right

Example fix

// before
String extractors = "...,order(0,-2),..."; // throws
// after
String extractors = "...,order(0,2),...";
Defensive patterns

Strategy: validation

Validate before calling

int right = Extractor.getParenthesizedNum(arg, 2);
if (right < 0) throw new IllegalArgumentException("order() right order must be >= 0 in: " + arg);

Try / catch

try {
  ExtractorFrames.getExtractorFrames(extractorsString);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Right order must be non-negative")) {
    // correct the order(...) spec
  } else { throw e; }
}

Prevention

When it happens

Trigger: Passing a feature spec like 'order(0,-3)' or 'order(-2,-1)' in the tagger's extractors string; getParenthesizedNum(arg, 2) returns a negative second number.

Common situations: Misreading the order() semantics and trying to look backward on the right side with a negative number; editing an existing extractors list and swapping the two arguments.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/ExtractorFrames.java:212

        // twoTags(-2,1) would give you 1 extractor for t-2, t+1
        int left = Extractor.getParenthesizedNum(arg, 1);
        int right = Extractor.getParenthesizedNum(arg, 2);
        extrs.add(new ExtractorTwoTags(left, right));
      } else if (arg.startsWith("lowercasewords(")) {
        // non-sequence features with just a certain number of lowercase words
        // to the left and right
        int lWindow = Extractor.getParenthesizedNum(arg, 1);
        int rWindow = Extractor.getParenthesizedNum(arg, 2);
        for (int i = lWindow; i <= rWindow; i++) {
          extrs.add(new ExtractorWordLowerCase(i));
        }
      } else if (arg.startsWith("order(")) {
        // anything like order(2), order(-4), order(0,3), or
        // order(-2,1) are okay.
        int leftOrder = Extractor.getParenthesizedNum(arg, 1);
        int rightOrder = Extractor.getParenthesizedNum(arg, 2);
        if (leftOrder > 0) { leftOrder = -leftOrder; }
	if (rightOrder < 0) { throw new IllegalArgumentException("Right order must be non-negative, not " + rightOrder); }
        // cdm 2009: We only add successively higher order tag k-grams
        // ending adjacent to t0.  Adding lower order features at a distance
        // appears not to help (Dec 2009). But they can now be added with tags().

        for (int idx = leftOrder ; idx <= rightOrder; idx++) {
          if (idx == -1 || idx == 1) {
            extrs.add(new Extractor(idx, true));
          } else if (idx != 0) {
            extrs.add(new ExtractorContinuousTagConjunction(idx));
          }
          // do nothing if idx = 0. You can't use the  tag to infer itself!
        }
      } else if (arg.startsWith("wordTag(")) {
        // sequence feature of a word and a tag: wordTag(-1,1)
        int posW = Extractor.getParenthesizedNum(arg, 1);
        int posT = Extractor.getParenthesizedNum(arg, 2);
        extrs.add(new ExtractorWordTag(posW, posT));
      } else if (arg.startsWith("wordTwoTags(")) {

View on GitHub (pinned to 1b7edd19c4)