{"record":{"id":"25ae2cf8db509c8a","repo":"apache/hadoop","slug":"no-more-entry-in-f-25ae2c","errorCode":null,"errorMessage":"No more entry in {f}","messagePattern":"No more entry in (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":1186,"sourceCode":"   * @throws UnresolvedLinkException unresolved link exception.\n   * @throws IOException raised on errors performing I/O.\n   * @return FileStatus Iterator.\n   */\n  public RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f)\n      throws AccessControlException, FileNotFoundException,\n      UnresolvedLinkException, IOException {\n    return new RemoteIterator<LocatedFileStatus>() {\n      private RemoteIterator<FileStatus> itor = listStatusIterator(f);\n      \n      @Override\n      public boolean hasNext() throws IOException {\n        return itor.hasNext();\n      }\n      \n      @Override\n      public LocatedFileStatus next() throws IOException {\n        if (!hasNext()) {\n          throw new NoSuchElementException(\"No more entry in \" + f);\n        }\n        FileStatus result = itor.next();\n        BlockLocation[] locs = null;\n        if (result.isFile()) {\n          locs = getFileBlockLocations(\n              result.getPath(), 0, result.getLen());\n        }\n        return new LocatedFileStatus(result, locs);\n      }\n    };\n  }\n\n  /**\n   * The specification of this method matches that of\n   * {@link FileContext.Util#listStatus(Path)} except that Path f must be \n   * for this file system.\n   * @param f the path.\n   * @throws AccessControlException access control exception.","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L1168-L1204","documentation":"The RemoteIterator<LocatedFileStatus> returned by listLocatedStatus wraps a plain listing iterator; calling next() after hasNext() returned false throws NoSuchElementException with the listed path ('No more entry in {f}'). This is ordinary iterator exhaustion, made easy to miss because RemoteIterator.next() declares IOException as well and loops often only catch that.","triggerScenarios":"Calling next() without a preceding hasNext() check; do/while loops that consume next() first and test hasNext() afterwards; iteration helpers that assume next() returns null at the end instead of throwing.","commonSituations":"Hand-rolled listing loops ported from java.util.Iterator idioms; merging several RemoteIterators in one loop; input formats and directory walkers iterating large listings where exhaustion is the normal exit path.","solutions":["Always guard consumption: while (it.hasNext()) { LocatedFileStatus s = it.next(); ... }","If an unguarded loop must be kept, catch NoSuchElementException separately from IOException as the termination signal","For small directories, prefer fc.util().listStatus(f) and iterate the returned array"],"exampleFix":"// before\nwhile (true) {\n  LocatedFileStatus s = itor.next(); // throws at end\n  process(s);\n}\n\n// after\nwhile (itor.hasNext()) {\n  process(itor.next());\n}","handlingStrategy":"validation","validationCode":"while (itor.hasNext()) {\n  LocatedFileStatus s = itor.next();\n  // process s\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call next() on a RemoteIterator without a preceding hasNext() check","Remember RemoteIterator.next() throws NoSuchElementException (unchecked), not IOException, at exhaustion","Prefer util().listStatus(f) for small directories where array semantics are simpler"],"tags":["iterator","nosuchelementexception","listlocatedstatus","off-by-one","hadoop-fs"],"backgroundTag":"iterator-exhausted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}