{"record":{"id":"96062b89a123195b","repo":"languagetool-org/languagetool","slug":"skip-should-be-between-1-and-byte-max-value","errorCode":null,"errorMessage":"'skip' should be between -1 and ${Byte.MAX_VALUE}","messagePattern":"'skip' should be between -1 and (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java","lineNumber":404,"sourceCode":"   * The minimum number of times the element needs to occur.\n   */\n  public int getMinOccurrence() {\n    return hasFlag(MAY_BE_OMITTED_MASK) ? 0 : 1;\n  }\n\n  /**\n   * The maximum number of times the element may occur.\n   */\n  public int getMaxOccurrence() {\n    return maxOccurrence;\n  }\n\n  /**\n   * @param i exception scope length.\n   */\n  public void setSkipNext(int i) {\n    if (i < -1 || i > Byte.MAX_VALUE) {\n      throw new IllegalArgumentException(\"'skip' should be between -1 and \" + Byte.MAX_VALUE);\n    }\n    skip = (byte) i;\n  }\n\n  /**\n   * The minimum number of times this element may occur.\n   * @param i currently only {@code 0} and {@code 1} are supported\n   */\n  public void setMinOccurrence(int i) {\n    if (i != 0 && i != 1) {\n      throw new IllegalArgumentException(\"minOccurrences must be 0 or 1: \" + i);\n    }\n    setFlag(MAY_BE_OMITTED_MASK, i == 0);\n  }\n\n  /**\n   * The maximum number of times this element may occur.\n   * @param i a number &gt;= 1 or {@code -1} for unlimited occurrences","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternToken.java#L386-L422","documentation":"PatternToken.setSkipNext(int) validates that the skip scope is -1 (infinite) or between 0 and Byte.MAX_VALUE (127), throwing IllegalArgumentException otherwise. LanguageTool stores skip as a byte, so larger values are unsupported by design. Negative values other than -1 are also invalid.","triggerScenarios":"Calling setSkipNext(-2) or setSkipNext(128 or more); also via pattern builders/XML when a rule's skip=\"200\" is parsed during build() (see testInfiniteSkip).","commonSituations":"Writing a rule that intends 'skip many tokens' with an oversized skip value; computing skip dynamically from a number that exceeds 127; typos like skip=\"1000\" intending 'unlimited' instead of skip=\"-1\".","solutions":["Use -1 for unlimited skip instead of a large positive number.","Clamp the skip value to Byte.MAX_VALUE (127) before calling setSkipNext if your value is computed.","Check the rule XML: change skip attributes >127 to 127 or -1.","Validate user-supplied scope numbers at config load time with a range check."],"exampleFix":"// before\npToken.setSkipNext(300);\n// after\npToken.setSkipNext(300 > Byte.MAX_VALUE ? -1 : 300); // or skip=\"-1\" in XML","handlingStrategy":"validation","validationCode":"public static int safeSkip(int i) {\n  if (i < -1 || i > Byte.MAX_VALUE) throw new IllegalArgumentException(\"skip must be -1..127: \" + i);\n  return i;\n}\n// call: pToken.setSkipNext(safeSkip(userSkip));","typeGuard":"boolean isValidSkip(int i) { return i >= -1 && i <= Byte.MAX_VALUE; }","tryCatchPattern":"try {\n  token.setSkipNext(skip);\n} catch (IllegalArgumentException e) {\n  token.setSkipNext(-1); // fall back to unlimited\n}","preventionTips":["Use -1 for unlimited skip; never a big positive number.","Clamp computed skips to Byte.MAX_VALUE.","Audit rule XML for skip attributes > 127.","Range-check user-supplied scope values at config load."],"tags":["validation","range-check","java"],"backgroundTag":"value-out-of-range","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}