{"record":{"id":"2fd46eb697840cb9","repo":"stanfordnlp/CoreNLP","slug":"invalid-region-end","errorCode":null,"errorMessage":"Invalid region end=","messagePattern":"Invalid region end=","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/SequenceMatcher.java","lineNumber":602,"sourceCode":"      return \"Matching not completed\";\n    } else if (!matched) {\n      return \"No match found\";\n    } else {\n      return \"Match successful\";\n    }\n  }\n\n  /**\n   * Set region to search in.\n   * @param start - start index\n   * @param end - end index (exclusive)\n   */\n  public void region(int start, int end) {\n    if (start < 0 || start > elements.size()) {\n      throw new IndexOutOfBoundsException(\"Invalid region start=\" + start + \", need to be between 0 and \" + elements.size());\n    }\n    if (end < 0 || end > elements.size()) {\n      throw new IndexOutOfBoundsException(\"Invalid region end=\" + end + \", need to be between 0 and \" + elements.size());\n    }\n    if (start > end) {\n      throw new IndexOutOfBoundsException(\"Invalid region end=\" + end + \", need to be larger then start=\" + start);\n    }\n    this.regionStart = start;\n    this.nextMatchStart = start;\n    this.regionEnd = end;\n  }\n\n  public int regionEnd()\n  {\n    return regionEnd;\n  }\n\n  public int regionStart()\n  {\n    return regionStart;\n  }","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/SequenceMatcher.java#L584-L620","documentation":"region(start, end) validates that end lies within [0, elements.size()]; when end is negative or beyond the list size it throws IndexOutOfBoundsException with 'Invalid region end='. This keeps the exclusive end bound inside the sequence.","triggerScenarios":"Calling matcher.region(start, end) with end < 0 or end > elements.size(), e.g. passing an exclusive end equal to size+1 or a negative window.","commonSituations":"Using length instead of size for the exclusive bound, stale offsets after the elements list changed, or computing end = start + windowLength that overruns the sequence.","solutions":["Clamp end to [0, elements.size()] before calling region()","Verify the end index is the exclusive bound and does not exceed elements.size()","Catch IndexOutOfBoundsException if the window is user-provided","Recompute end from the live elements list size"],"exampleFix":"// before\nmatcher.region(start, start + windowLen); // may exceed size\n// after\nmatcher.region(start, Math.min(start + windowLen, elements.size()));","handlingStrategy":"validation","validationCode":"if (end < 0 || end > elements.size()) {\n  throw new IllegalArgumentException(\"region end out of range: \" + end);\n}\nmatcher.region(start, end);","typeGuard":"boolean isValidEnd(int end, List<?> elements) {\n  return end >= 0 && end <= elements.size();\n}","tryCatchPattern":"try {\n  matcher.region(start, end);\n} catch (IndexOutOfBoundsException e) {\n  log.warn(\"Invalid region end\", e);\n  matcher.region(start, elements.size());\n}","preventionTips":["Remember end is exclusive and capped at elements.size()","Clamp end = Math.min(end, elements.size())","Recompute end whenever the underlying sequence changes"],"tags":["java","index-out-of-bounds","tokensregex"],"backgroundTag":"index-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"}