{"record":{"id":"2789aed3fe744b75","repo":"stanfordnlp/CoreNLP","slug":"right-order-must-be-non-negative-not-rightorder","errorCode":null,"errorMessage":"Right order must be non-negative, not ${rightOrder}","messagePattern":"Right order must be non-negative, not (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/tagger/maxent/ExtractorFrames.java","lineNumber":212,"sourceCode":"        // twoTags(-2,1) would give you 1 extractor for t-2, t+1\n        int left = Extractor.getParenthesizedNum(arg, 1);\n        int right = Extractor.getParenthesizedNum(arg, 2);\n        extrs.add(new ExtractorTwoTags(left, right));\n      } else if (arg.startsWith(\"lowercasewords(\")) {\n        // non-sequence features with just a certain number of lowercase words\n        // to the left and right\n        int lWindow = Extractor.getParenthesizedNum(arg, 1);\n        int rWindow = Extractor.getParenthesizedNum(arg, 2);\n        for (int i = lWindow; i <= rWindow; i++) {\n          extrs.add(new ExtractorWordLowerCase(i));\n        }\n      } else if (arg.startsWith(\"order(\")) {\n        // anything like order(2), order(-4), order(0,3), or\n        // order(-2,1) are okay.\n        int leftOrder = Extractor.getParenthesizedNum(arg, 1);\n        int rightOrder = Extractor.getParenthesizedNum(arg, 2);\n        if (leftOrder > 0) { leftOrder = -leftOrder; }\n\tif (rightOrder < 0) { throw new IllegalArgumentException(\"Right order must be non-negative, not \" + rightOrder); }\n        // cdm 2009: We only add successively higher order tag k-grams\n        // ending adjacent to t0.  Adding lower order features at a distance\n        // appears not to help (Dec 2009). But they can now be added with tags().\n\n        for (int idx = leftOrder ; idx <= rightOrder; idx++) {\n          if (idx == -1 || idx == 1) {\n            extrs.add(new Extractor(idx, true));\n          } else if (idx != 0) {\n            extrs.add(new ExtractorContinuousTagConjunction(idx));\n          }\n          // do nothing if idx = 0. You can't use the  tag to infer itself!\n        }\n      } else if (arg.startsWith(\"wordTag(\")) {\n        // sequence feature of a word and a tag: wordTag(-1,1)\n        int posW = Extractor.getParenthesizedNum(arg, 1);\n        int posT = Extractor.getParenthesizedNum(arg, 2);\n        extrs.add(new ExtractorWordTag(posW, posT));\n      } else if (arg.startsWith(\"wordTwoTags(\")) {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/tagger/maxent/ExtractorFrames.java#L194-L230","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the right order non-negative, e.g. use order(-2,1) instead of order(-2,-1)","Remember left order may be negative (tags to the left) but right order counts tags to the right and must be >= 0","If you only want left context, use order(-3,0)","Double-check the argument order: first number is left (may be negated), second is right"],"exampleFix":"// before\nString extractors = \"...,order(0,-2),...\"; // throws\n// after\nString extractors = \"...,order(0,2),...\";","handlingStrategy":"validation","validationCode":"int right = Extractor.getParenthesizedNum(arg, 2);\nif (right < 0) throw new IllegalArgumentException(\"order() right order must be >= 0 in: \" + arg);","typeGuard":null,"tryCatchPattern":"try {\n  ExtractorFrames.getExtractorFrames(extractorsString);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Right order must be non-negative\")) {\n    // correct the order(...) spec\n  } else { throw e; }\n}","preventionTips":["Treat order(l,r) as l <= 0 (left context) and r >= 0 (right context)","Clamp or validate numeric args of order(...) before passing them into the extractors string","Add a config lint step that checks order() specs at startup","Read the order() docs to avoid negating the right window"],"tags":["java","pos-tagger","range","feature-spec"],"backgroundTag":"value-out-of-range","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"}