{"record":{"id":"155b7a2f034d9477","repo":"apache/hadoop","slug":"no-more-elements-155b7a","errorCode":null,"errorMessage":"No more elements","messagePattern":"No more elements","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java","lineNumber":1389,"sourceCode":"      public boolean hasNext() throws IOException {\n        if (currIter.hasNext()) {\n          return true;\n        }\n        while (currIdx < iters.size()) {\n          currIter = iters.get(currIdx++);\n          if (currIter.hasNext()) {\n            return true;\n          }\n        }\n        return false;\n      }\n\n      @Override\n      public CacheDirectiveEntry next() throws IOException {\n        if (hasNext()) {\n          return currIter.next();\n        }\n        throw new NoSuchElementException(\"No more elements\");\n      }\n    };\n  }\n\n  //Currently Cache pool APIs supported only in default cluster.\n  @Override\n  public void addCachePool(CachePoolInfo info) throws IOException {\n    if (this.vfs == null) {\n      super.addCachePool(info);\n      return;\n    }\n    List<IOException> failedExceptions = new ArrayList<>();\n    boolean isDFSExistsInChilds = false;\n\n    for (FileSystem fs : getChildFileSystems()) {\n      if (!(fs instanceof DistributedFileSystem)) {\n        continue;\n      }","sourceCodeStart":1371,"sourceCodeEnd":1407,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java#L1371-L1407","documentation":"The anonymous RemoteIterator returned by ViewDistributedFileSystem.listCacheDirectives throws NoSuchElementException(\"No more elements\") from next() when hasNext() is false, i.e. every chained per-cluster directive iterator is exhausted. This is standard Java iterator contract behavior, not an HDFS service problem.","triggerScenarios":"Calling next() without checking hasNext(), or calling it again after hasNext() returned false, on the iterator from listCacheDirectives (or from the chained iterator wrapper).","commonSituations":"Custom loops that call next() once per row unconditionally; code assuming at least one directive exists on every cluster; test code iterating empty results.","solutions":["Always drive the iterator with while (it.hasNext()) { it.next(); }","Treat an empty iteration as a normal result (no cache directives on any child cluster)"],"exampleFix":"// before\nCacheDirectiveEntry e = it.next();\n\n// after\nwhile (it.hasNext()) {\n  CacheDirectiveEntry e = it.next();\n}","handlingStrategy":"validation","validationCode":"RemoteIterator<CacheDirectiveEntry> it = vfs.listCacheDirectives(filter);\nwhile (it.hasNext()) { // guard every next() with hasNext()\n  CacheDirectiveEntry entry = it.next();\n  process(entry);\n}","typeGuard":null,"tryCatchPattern":"try {\n  CacheDirectiveEntry e = it.next();\n} catch (NoSuchElementException nsee) {\n  // iteration exhausted: treat as end-of-data, not an error","preventionTips":["Never call RemoteIterator.next() without a preceding hasNext() check","Treat empty results as valid output; do not assume at least one entry exists"],"tags":["hdfs","viewfs","iterator","centralized-caching"],"backgroundTag":"iterator-no-such-element","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}