{"record":{"id":"1100b7306c842237","repo":"apache/hadoop","slug":"no-more-entries","errorCode":null,"errorMessage":"No more entries","messagePattern":"No more entries","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java","lineNumber":1529,"sourceCode":"      // If we're done with the current batch, try to get the next batch\n      if (listingIdx >= batchedListing.getListings().length) {\n        if (!batchedListing.hasMore()) {\n          LBI_LOG.trace(\"No more elements\");\n          return false;\n        }\n        batchedListing = dfs.batchedListPaths(\n            srcs, batchedListing.getStartAfter(), needLocation);\n        LBI_LOG.trace(\"Got batchedListing: {}\", batchedListing);\n        listingIdx = 0;\n      }\n      return listingIdx < batchedListing.getListings().length;\n    }\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public PartialListing<T> next() throws IOException {\n      if (!hasNext()) {\n        throw new NoSuchElementException(\"No more entries\");\n      }\n      HdfsPartialListing listing = batchedListing.getListings()[listingIdx];\n      listingIdx++;\n\n      Path parent = paths.get(listing.getParentIdx());\n\n      if (listing.getException() != null) {\n        return new PartialListing<>(parent, listing.getException());\n      }\n\n      // Qualify paths for the client.\n      List<HdfsFileStatus> statuses = listing.getPartialListing();\n      List<T> qualifiedStatuses =\n          Lists.newArrayListWithCapacity(statuses.size());\n\n      for (HdfsFileStatus status : statuses) {\n        if (needLocation) {\n          qualifiedStatuses.add((T)((HdfsLocatedFileStatus) status)","sourceCodeStart":1511,"sourceCodeEnd":1547,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java#L1511-L1547","documentation":"PartialListingIterator.next() checks hasNext() first and throws NoSuchElementException('No more entries') when the batched listing is exhausted. This is the standard RemoteIterator contract violation path: the caller asked for an element after the iterator finished. Unlike the IOExceptions around it, this is an unchecked RuntimeException signalling caller misuse.","triggerScenarios":"Calling next() without a preceding true result from hasNext(), or calling next() a final time after a hasNext() that returned false; also loops like do/while that assume at least one element exists on an empty batch.","commonSituations":"while(it.next())-style loops written against Iterator (java.util) semantics; reusing an iterator after a break; adapting code from java.util.Iterator where hasNext/next have the same contract but developers forget RemoteIterator.next() throws IOException; empty directory lists passed to the batched API.","solutions":["Guard every next() with if (!it.hasNext()) break; before consuming.","Rewrite do/while loops as while (it.hasNext()) loops.","For empty input lists, skip iterator creation entirely.","If bridging to java.util streams, wrap RemoteIterator in a proper guava Iterator adapter that peeks hasNext()."],"exampleFix":"// before\ndo {\n  PartialListing<FileStatus> pl = it.next();\n  process(pl);\n} while (true); // eventually throws NoSuchElementException\n\n// after\nwhile (it.hasNext()) {\n  PartialListing<FileStatus> pl = it.next();\n  process(pl);\n}","handlingStrategy":"validation","validationCode":"if (paths.stream().allMatch(p -> false)) { /* empty input */ }\n// real guard is the loop shape:\nwhile (it.hasNext()) { PartialListing<FileStatus> pl = it.next(); }","typeGuard":null,"tryCatchPattern":"try {\n  PartialListing<FileStatus> pl = it.next();\n} catch (NoSuchElementException e) {\n  // iterator exhausted: should not happen if hasNext() is honored\n}","preventionTips":["Always call hasNext() immediately before next(); never assume a non-empty batch.","Rewrite do/while loops over RemoteIterator as while(it.hasNext()).","When adapting RemoteIterator to java.util.Iterator, cache the hasNext result in a peeked field."],"tags":["hdfs","remote-iterator","no-such-element-exception","iterator-misuse","distributed-filesystem"],"backgroundTag":"iterator-exhausted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}