apache/hadoop · error · NoSuchElementException

No more elements

Error message

No more elements

What it means

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.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/ViewDistributedFileSystem.java:1389

      public boolean hasNext() throws IOException {
        if (currIter.hasNext()) {
          return true;
        }
        while (currIdx < iters.size()) {
          currIter = iters.get(currIdx++);
          if (currIter.hasNext()) {
            return true;
          }
        }
        return false;
      }

      @Override
      public CacheDirectiveEntry next() throws IOException {
        if (hasNext()) {
          return currIter.next();
        }
        throw new NoSuchElementException("No more elements");
      }
    };
  }

  //Currently Cache pool APIs supported only in default cluster.
  @Override
  public void addCachePool(CachePoolInfo info) throws IOException {
    if (this.vfs == null) {
      super.addCachePool(info);
      return;
    }
    List<IOException> failedExceptions = new ArrayList<>();
    boolean isDFSExistsInChilds = false;

    for (FileSystem fs : getChildFileSystems()) {
      if (!(fs instanceof DistributedFileSystem)) {
        continue;
      }

View on GitHub (pinned to 2add963021)

Solutions

  1. Always drive the iterator with while (it.hasNext()) { it.next(); }
  2. Treat an empty iteration as a normal result (no cache directives on any child cluster)

Example fix

// before
CacheDirectiveEntry e = it.next();

// after
while (it.hasNext()) {
  CacheDirectiveEntry e = it.next();
}
Defensive patterns

Strategy: validation

Validate before calling

RemoteIterator<CacheDirectiveEntry> it = vfs.listCacheDirectives(filter);
while (it.hasNext()) { // guard every next() with hasNext()
  CacheDirectiveEntry entry = it.next();
  process(entry);
}

Try / catch

try {
  CacheDirectiveEntry e = it.next();
} catch (NoSuchElementException nsee) {
  // iteration exhausted: treat as end-of-data, not an error

Prevention

When it happens

Trigger: Calling next() without checking hasNext(), or calling it again after hasNext() returned false, on the iterator from listCacheDirectives (or from the chained iterator wrapper).

Common situations: Custom loops that call next() once per row unconditionally; code assuming at least one directive exists on every cluster; test code iterating empty results.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/155b7a2f034d9477. Report an issue: GitHub.