languagetool-org/languagetool · error · IllegalArgumentException
fromPos must be < toPos: fromPos: " + fromPos + ", toPos: "
Error message
fromPos must be < toPos: fromPos: " + fromPos + ", toPos: " + toPos
What it means
Constructor validation of the NERService.Span value class: a span with fromPos >= toPos is empty or reversed and cannot denote a text range. Generic argument guard — fires when callers pass swapped or bogus offsets, typically from misparsed NER output offsets.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/tagging/ner/NERService.java:150
return res;
}
private int getLastSlashFrom(String s, int startPos) {
for (int i = startPos; i >= 0; i--) {
char ch = s.charAt(i);
if (ch == '/') {
return i;
}
}
return -1;
}
public static class Span {
private final int fromPos;
private final int toPos;
public Span(int fromPos, int toPos) {
if (fromPos >= toPos) {
throw new IllegalArgumentException("fromPos must be < toPos: fromPos: " + fromPos + ", toPos: " + toPos);
}
this.fromPos = fromPos;
this.toPos = toPos;
}
public int getStart() {
return fromPos;
}
public int getEnd() {
return toPos;
}
@Override
public String toString() {
return fromPos + "-" + toPos;
}
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Ensure NER output offsets are parsed correctly and ordered start-before-end
- Swap the arguments if they were passed in reverse
- Handle zero-length spans separately instead of constructing an invalid Span
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/tagging/ner/NERService.java:150 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/47dd96acff5dafde.
Report an issue: GitHub.