stanfordnlp/CoreNLP · error · IndexOutOfBoundsException
Invalid region end=
Error message
Invalid region end=
What it means
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.
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
Example fix
// before matcher.region(start, start + windowLen); // may exceed size // after matcher.region(start, Math.min(start + windowLen, elements.size()));
Defensive patterns
Strategy: validation
Validate before calling
if (end < 0 || end > elements.size()) {
throw new IllegalArgumentException("region end out of range: " + end);
}
matcher.region(start, end); Type guard
boolean isValidEnd(int end, List<?> elements) {
return end >= 0 && end <= elements.size();
} Try / catch
try {
matcher.region(start, end);
} catch (IndexOutOfBoundsException e) {
log.warn("Invalid region end", e);
matcher.region(start, elements.size());
} Prevention
- Remember end is exclusive and capped at elements.size()
- Clamp end = Math.min(end, elements.size())
- Recompute end whenever the underlying sequence changes
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid region start=
- Annotation field cannot be null
- Attribute already defined:
- Attribute already defined
- Attribute match already defined:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/2fd46eb697840cb9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ling/tokensregex/SequenceMatcher.java:602
return "Matching not completed";
} else if (!matched) {
return "No match found";
} else {
return "Match successful";
}
}
/**
* Set region to search in.
* @param start - start index
* @param end - end index (exclusive)
*/
public void region(int start, int end) {
if (start < 0 || start > elements.size()) {
throw new IndexOutOfBoundsException("Invalid region start=" + start + ", need to be between 0 and " + elements.size());
}
if (end < 0 || end > elements.size()) {
throw new IndexOutOfBoundsException("Invalid region end=" + end + ", need to be between 0 and " + elements.size());
}
if (start > end) {
throw new IndexOutOfBoundsException("Invalid region end=" + end + ", need to be larger then start=" + start);
}
this.regionStart = start;
this.nextMatchStart = start;
this.regionEnd = end;
}
public int regionEnd()
{
return regionEnd;
}
public int regionStart()
{
return regionStart;
}View on GitHub (pinned to 1b7edd19c4)