{"record":{"id":"ee339b9420058182","repo":"apache/hadoop","slug":"invalid-start-or-len-parameter","errorCode":null,"errorMessage":"Invalid start or len parameter","messagePattern":"Invalid start or len parameter","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":890,"sourceCode":"   *   \"host2:9866\",\"host3:9866\",\"host4:9866\",\"host5:9866\"})\n   * BlockLocation(offset: 3 * BLOCK_SIZE, length: 123, hosts: {\"host1:9866\",\n   *   \"host4:9866\", \"host5:9866\"})\n   * </pre>\n   *\n   * @param file FilesStatus to get data from\n   * @param start offset into the given file\n   * @param len length for which to get locations for\n   * @throws IOException IO failure\n   * @return block location array.\n   */\n  public BlockLocation[] getFileBlockLocations(FileStatus file,\n      long start, long len) throws IOException {\n    if (file == null) {\n      return null;\n    }\n\n    if (start < 0 || len < 0) {\n      throw new IllegalArgumentException(\"Invalid start or len parameter\");\n    }\n\n    if (file.getLen() <= start) {\n      return new BlockLocation[0];\n\n    }\n    String[] name = {\"localhost:9866\"};\n    String[] host = {\"localhost\"};\n    return new BlockLocation[] {\n      new BlockLocation(name, host, 0, file.getLen()) };\n  }\n\n  /**\n   * Return an array containing hostnames, offset and size of\n   * portions of the given file.  For a nonexistent\n   * file or regions, {@code null} is returned.\n   *\n   * This call is most helpful with location-aware distributed","sourceCodeStart":872,"sourceCodeEnd":908,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L872-L908","documentation":"Pure argument validation in getFileBlockLocations(FileStatus,start,len): a negative start or a negative len throws IllegalArgumentException before any location lookup. The companion case, start beyond EOF, is not an error - it returns an empty BlockLocation[].","triggerScenarios":"Computing ranges as start/end and passing len = end - start when end < start; passing -1 as a sentinel; custom InputFormat split math receiving stale or truncated file lengths.","commonSituations":"Custom InputFormat/RecordReader range arithmetic; files concurrently truncated so status.getLen() is smaller than a previously computed start; off-by-one bugs in offset math.","solutions":["Clamp inputs: skip the call when start < 0 or len <= 0","Treat len == 0 or start >= file length as 'no blocks' and short-circuit (matches API behavior)","Fix the upstream arithmetic that produced the negative value - the exception is a symptom, not the bug"],"exampleFix":"// before\nBlockLocation[] locs = fs.getFileBlockLocations(status, start, end - start);\n\n// after\nlong len = end - start;\nBlockLocation[] locs = (start < 0 || len <= 0)\n    ? new BlockLocation[0]\n    : fs.getFileBlockLocations(status, start, len);","handlingStrategy":"validation","validationCode":"long len = end - start;\nif (start < 0 || len < 0) {\n  throw new IllegalArgumentException(\"bad range: start=\" + start + \" len=\" + len);\n}\nBlockLocation[] locs = fs.getFileBlockLocations(status, start, len);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate computed ranges at the point where they are computed","Never pass -1 sentinels into range APIs","Short-circuit zero-length ranges instead of calling the API"],"tags":["hadoop","filesystem","argument-validation","block-location"],"backgroundTag":"invalid-argument-range","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}