oracle/graal · error · IllegalArgumentException
got illegal fromIndex value: %d. fromIndex must be >= region
Error message
got illegal fromIndex value: %d. fromIndex must be >= regionFrom (%d) and <= regionTo (%d)
What it means
In RegexExecNode's 5-argument form, the search start index fromIndex must lie inside the declared region: regionFrom <= fromIndex <= regionTo. An out-of-region fromIndex throws IllegalArgumentException.
Source
Thrown at regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/RegexExecNode.java:93
}
final int toIndex;
final int regionFrom;
final int regionTo;
if (args.length == 5) {
long toIndexLong = toLongNode.execute(args[2]);
long regionFromLong = toLongNode.execute(args[3]);
long regionToLong = toLongNode.execute(args[4]);
if (regionFromLong < 0 || regionFromLong > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalArgumentException(String.format("got illegal regionFrom value: %d. regionFrom must be >= 0 and <= input length (%d)", regionFromLong, length));
}
if (regionToLong < regionFromLong || regionToLong > length) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalArgumentException(String.format("got illegal regionTo value: %d. regionTo must be >= regionFrom (%d) and <= input length (%d)", regionToLong, regionFromLong, length));
}
if (fromIndex < regionFromLong || fromIndex > regionToLong) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalArgumentException(
String.format("got illegal fromIndex value: %d. fromIndex must be >= regionFrom (%d) and <= regionTo (%d)", fromIndex, regionFromLong, regionToLong));
}
if (toIndexLong < fromIndex || toIndexLong > regionToLong) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new IllegalArgumentException(String.format("got illegal toIndex value: %d. toIndex must be >= fromIndex (%d) and <= regionTo (%d)", toIndexLong, fromIndex, regionToLong));
}
if (toIndexLong != regionToLong) {
CompilerDirectives.transferToInterpreterAndInvalidate();
throw new UnsupportedOperationException(String.format("got non-equal toIndex (%d) and regionTo (%d), support for this is not implemented yet", toIndexLong, regionToLong));
}
toIndex = (int) toIndexLong;
regionFrom = (int) regionFromLong;
regionTo = (int) regionToLong;
} else {
assert args.length == 2;
toIndex = length;
regionFrom = 0;
regionTo = length;View on GitHub (pinned to a66e9ccd1d)
Solutions
- Clamp fromIndex into the region: fromIndex = Math.max(regionFrom, Math.min(fromIndex, regionTo)).
- Reset lastIndex/nextSearchIndex to regionFrom whenever a region is applied.
- Double-check whether your API contract treats fromIndex as absolute or region-relative and convert accordingly.
Example fix
// before exec(input, lastIndex, regionTo, regionFrom, regionTo); // lastIndex may be < regionFrom // after lastIndex = Math.max(regionFrom, Math.min(lastIndex, regionTo)); exec(input, lastIndex, regionTo, regionFrom, regionTo);
Defensive patterns
Strategy: validation
Validate before calling
static boolean validFromIndex(long fromIndex, long regionFrom, long regionTo) {
return fromIndex >= regionFrom && fromIndex <= regionTo;
} Prevention
- Reset the search start index to regionFrom whenever a region is applied.
- Clamp fromIndex into [regionFrom, regionTo] before invoking exec.
- Document clearly whether your API's start index is absolute or region-relative.
When it happens
Trigger: Calling 5-arg exec with fromIndex < regionFrom or fromIndex > regionTo, e.g. fromIndex=0 with regionFrom=5, or fromIndex=input.length() while regionTo is smaller.
Common situations: Reusing a lastIndex from an unbounded search together with a narrowed region (e.g. emulating Matcher.region().find(lastIndex)); adapters that pass the string offset as fromIndex while the engine expects a region-relative start.
Related errors
- got illegal regionFrom value: %d. regionFrom must be >= 0 an
- got illegal regionTo value: %d. regionTo must be >= regionFr
- got illegal toIndex value: %d. toIndex must be >= fromIndex
- got non-equal toIndex (%d) and regionTo (%d), support for th
- got illegal fromIndex value: %d. fromIndex must be >= 0 and
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/4801e71a77fc9d20.
Report an issue: GitHub.