apache/hadoop · warning · NoSuchElementException

No more corrupt file blocks

Error message

No more corrupt file blocks

What it means

CorruptFileBlockIterator paginates the NameNode's list of corrupt files (listCorruptFileBlocks) and implements the standard Iterator contract: next() throws NoSuchElementException once nextPath is null. Because nextPath starts null when the first listing returns zero corrupt files, any unguarded next() call — first or after exhaustion — is a caller bug, not a cluster problem.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/client/impl/CorruptFileBlockIterator.java:97

      // there are no more corrupt file blocks
      nextPath = null;
    } else {
      nextPath = string2Path(files[fileIdx]);
      fileIdx++;
    }
  }


  @Override
  public boolean hasNext() {
    return nextPath != null;
  }


  @Override
  public Path next() throws IOException {
    if (!hasNext()) {
      throw new NoSuchElementException("No more corrupt file blocks");
    }

    Path result = nextPath;
    loadNext();

    return result;
  }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Always guard with hasNext(): while (it.hasNext()) { Path p = it.next(); ... }.
  2. Handle the zero-iteration case gracefully — an empty iteration is a healthy result.
  3. Keep pagination looping until hasNext() is false; the iterator fetches further batches itself.

Example fix

// before
do {
  Path p = it.next();
  audit(p);
} while (true);

// after
while (it.hasNext()) {
  Path p = it.next();
  audit(p);
}
Defensive patterns

Strategy: validation

Validate before calling

RemoteIterator<Path> it = dfs.listCorruptFileBlocks(path);
while (it.hasNext()) { // mandatory guard: listing may be empty
  Path corrupt = it.next();
  handle(corrupt);
}

Prevention

When it happens

Trigger: Calling next() without guarding hasNext() (do/while loops, assumed non-empty listing); calling next() immediately on a healthy cluster where the first listCorruptFileBlocks response contains zero paths.

Common situations: Custom monitoring code scanning for corrupt files; loops converted from for-each to manual iterator handling; scripts that assume at least one corrupt file exists when corruption is suspected.

Related errors


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