{"record":{"id":"1f44f533c2ed4512","repo":"apache/hadoop","slug":"attempt-to-seek-after-the-end-location","errorCode":null,"errorMessage":"Attempt to seek after the end location.","messagePattern":"Attempt to seek after the end location\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/TFile.java","lineNumber":1413,"sourceCode":"      }\n\n      /**\n       * Move the cursor to the new location. The entry returned by the previous\n       * entry() call will be invalid.\n       * \n       * @param l\n       *          new cursor location. It must fall between the begin and end\n       *          location of the scanner.\n       * @throws IOException\n       */\n      private void seekTo(Location l) throws IOException {\n        if (l.compareTo(beginLocation) < 0) {\n          throw new IllegalArgumentException(\n              \"Attempt to seek before the begin location.\");\n        }\n\n        if (l.compareTo(endLocation) > 0) {\n          throw new IllegalArgumentException(\n              \"Attempt to seek after the end location.\");\n        }\n\n        if (l.compareTo(endLocation) == 0) {\n          parkCursorAtEnd();\n          return;\n        }\n\n        if (l.getBlockIndex() != currentLocation.getBlockIndex()) {\n          // going to a totally different block\n          initBlock(l.getBlockIndex());\n        } else {\n          if (valueChecked) {\n            // may temporarily go beyond the last record in the block (in which\n            // case the next if loop will always be true).\n            inBlockAdvance(1);\n          }\n          if (l.getRecordIndex() < currentLocation.getRecordIndex()) {","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/file/tfile/TFile.java#L1395-L1431","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nLocation target = resolveLocation(offset);\nscanner.seekTo/key-based seek that lands past endLocation); // IllegalArgumentException\n\n// after\nLocation target = resolveLocation(offset);\nif (target.compareTo(scanner.end()) > 0) {\n  target = scanner.end(); // park at end instead of throwing\n}\n// then seek","handlingStrategy":"validation","validationCode":"// Clamp targets past the end: park at end instead of throwing\nLocation target = computeTarget(reader, offset);\nif (target.compareTo(scanner.end()) > 0) {\n  target = scanner.end(); // scanner.atEnd() becomes true; loop terminates normally\n}\n// then perform the seek with the clamped location","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"after the end location\")) {\n    // treat as end-of-range: stop scanning this split\n  }\n}","preventionTips":["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"],"tags":["hadoop","tfile","scanner","seek","out-of-range"],"backgroundTag":"seek-out-of-range","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}