apache/hadoop · error · IllegalArgumentException
Attempt to seek after the end location.
Error message
Attempt to seek after the end location.
What it means
Thrown by the Scanner's private seekTo(Location) when the target location sorts after the scanner's end location. Together with the before-begin check it enforces that every seek stays within the [begin, end) window the Scanner was constructed over. Violations surface as IllegalArgumentException, typically via public seek methods that resolved a key or record number to an out-of-window location.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/TFile.java:1413
}
/**
* Move the cursor to the new location. The entry returned by the previous
* entry() call will be invalid.
*
* @param l
* new cursor location. It must fall between the begin and end
* location of the scanner.
* @throws IOException
*/
private void seekTo(Location l) throws IOException {
if (l.compareTo(beginLocation) < 0) {
throw new IllegalArgumentException(
"Attempt to seek before the begin location.");
}
if (l.compareTo(endLocation) > 0) {
throw new IllegalArgumentException(
"Attempt to seek after the end location.");
}
if (l.compareTo(endLocation) == 0) {
parkCursorAtEnd();
return;
}
if (l.getBlockIndex() != currentLocation.getBlockIndex()) {
// going to a totally different block
initBlock(l.getBlockIndex());
} else {
if (valueChecked) {
// may temporarily go beyond the last record in the block (in which
// case the next if loop will always be true).
inBlockAdvance(1);
}
if (l.getRecordIndex() < currentLocation.getRecordIndex()) {View on GitHub (pinned to 2add963021)
Solutions
- Validate the target against the scanner's range before seeking, or create the scanner over the full file when arbitrary seeks are needed
- Clamp targets past the end to the end location (scanner parks at end; atEnd() returns true) instead of letting the exception escape
- Derive seek locations only from the same Reader instance and range that built the scanner
Example fix
// before
Location target = resolveLocation(offset);
scanner.seekTo/key-based seek that lands past endLocation); // IllegalArgumentException
// after
Location target = resolveLocation(offset);
if (target.compareTo(scanner.end()) > 0) {
target = scanner.end(); // park at end instead of throwing
}
// then seek Defensive patterns
Strategy: validation
Validate before calling
// Clamp targets past the end: park at end instead of throwing
Location target = computeTarget(reader, offset);
if (target.compareTo(scanner.end()) > 0) {
target = scanner.end(); // scanner.atEnd() becomes true; loop terminates normally
}
// then perform the seek with the clamped location Try / catch
catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("after the end location")) {
// treat as end-of-range: stop scanning this split
}
} Prevention
- Always check/cap computed locations against the scanner's end before seeking
- Treat end-of-range as a normal termination condition, not an error
- Never mix locations from one reader with a scanner built on another reader instance
When it happens
Trigger: Seeking to a key whose block is beyond the scanner's end location (e.g. a range scanner over early blocks); passing a record number or offset from the full file to a scanner bound to a sub-range.
Common situations: Range-restricted scanning (parallel splits, pagination) with seek targets computed against the whole file; off-by-one when converting an end-exclusive offset to a Location; stale locations used after re-creating a scanner with a narrower range.
Related errors
- Attempt to seek before the begin location.
- Seeking in unsorted TFile
- No key-value to read
- Cannot seek to a negative offset " + targetPos
- Attempted to seek or read past the end of the file " + targe
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/1f44f533c2ed4512.
Report an issue: GitHub.