apache/beam · error · NoSuchElementException

No block has been successfully read from " + getCurrentSourc

Error message

No block has been successfully read from " + getCurrentSource()

What it means

BlockBasedSource.BlockBasedReader.getCurrent() returns the current record of the current block; if no block has been successfully read yet (getCurrentBlock() returns null) there is no record to return, so it throws NoSuchElementException per the BoundedSource.Reader contract.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/BlockBasedSource.java:181

     *
     * <p>This method and {@link Block#getFractionOfBlockConsumed} are used to provide an estimate
     * of progress within a block ({@code getCurrentBlock().getFractionOfBlockConsumed() *
     * getCurrentBlockSize()}). It is acceptable for the result of this computation to be {@code 0},
     * but progress estimation will be inaccurate.
     */
    public abstract long getCurrentBlockSize();

    /**
     * Returns the largest offset such that starting to read from that offset includes the current
     * block.
     */
    public abstract long getCurrentBlockOffset();

    @Override
    public final T getCurrent() throws NoSuchElementException {
      Block<T> currentBlock = getCurrentBlock();
      if (currentBlock == null) {
        throw new NoSuchElementException(
            "No block has been successfully read from " + getCurrentSource());
      }
      return currentBlock.getCurrentRecord();
    }

    /**
     * Returns true if the reader is at a split point. A {@code BlockBasedReader} is at a split
     * point if the current record is the first record in a block. In other words, split points are
     * block boundaries.
     */
    @Override
    public boolean isAtSplitPoint() {
      return atSplitPoint;
    }

    /**
     * Reads the next record from the {@link #getCurrentBlock() current block} if possible. Will
     * call {@link #readNextBlock()} to advance to the next block if not.

View on GitHub (pinned to 12126d8942)

Solutions

  1. Call reader.start() and check its return value before accessing getCurrent()
  2. Only read getCurrent() when the previous start()/readNextBlock()/advance() returned true
  3. Guard with getCurrentBlock() != null before calling getCurrent()
  4. Ensure the reader was properly prepared/initialized by the runner before use

Example fix

// before
T value = reader.getCurrent();
// after
if (reader.start()) {
  T value = reader.getCurrent();
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (reader.getCurrentBlock() == null) {
  throw new IllegalStateException("call start() before getCurrent()");
}

Type guard

static <T> boolean hasCurrent(BlockBasedSource.BlockBasedReader<T> r) {
  return r.getCurrentBlock() != null;
}

Try / catch

try {
  T v = reader.getCurrent();
} catch (NoSuchElementException e) {
  // reader not started or exhausted
}

Prevention

When it happens

Trigger: Calling reader.getCurrent() before the first successful read (before start()/advance() populated the current block), or after a failed initial read.

Common situations: Custom source code inspecting getCurrent() immediately after reader creation; runner code probing current values before initiating reads; first-block read failures leaving the reader unpositioned.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/633ba0ecf2329c07. Report an issue: GitHub.