apache/beam · error · NoSuchElementException

Current timestamp is unavailable because either the reader…

Error message

Current timestamp is unavailable because either the reader is at the beginning of the input and start() or advance() wasn't called, or the last start() or advance() returned false.

What it means

SyntheticUnboundedSource's reader.getCurrentTimestamp() throws NoSuchElementException when the eventTime field is null, meaning the reader is not positioned at a record: start()/advance() was never called successfully, or the last call returned false. Per the Beam reader contract, timestamps are only available alongside a current element.

Solutions

  1. Ensure start() was called and returned true (or the last advance() returned true) before calling getCurrentTimestamp().
  2. Guard the read: only ask for the timestamp immediately after obtaining a current element via getCurrent().
  3. Verify synthetic source options configure event time if your harness requires timestamps.

Example fix

// before
Instant ts = reader.getCurrentTimestamp();
// after
if (reader.start()) {
  Instant ts = reader.getCurrentTimestamp();
}
Defensive patterns

Strategy: try-catch

Type guard

boolean hasTimestamp(UnboundedSource.UnboundedReader<?> r) { try { r.getCurrentTimestamp(); return true; } catch (NoSuchElementException e) { return false; } }

Try / catch

try {
  Instant ts = reader.getCurrentTimestamp();
} catch (NoSuchElementException e) {
  // no current element: position reader via start()/advance() first
}

Prevention

When it happens

Trigger: Calling getCurrentTimestamp() before start() succeeds or after advance() returns false; or calling it without a current element when the synthetic source's event-time configuration left eventTime unset.

Common situations: Custom runner or test code that requests the element's timestamp out of order; synthetic options that produce records without event time combined with timestamp-reading harness code.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/io/synthetic/src/main/java/org/apache/beam/sdk/io/synthetic/SyntheticUnboundedSource.java:168

    public SyntheticUnboundedSource getCurrentSource() {
      return source;
    }

    @Override
    public KV<byte[], byte[]> getCurrent() throws NoSuchElementException {
      if (currentKVPair == null) {
        throw new NoSuchElementException(
            "Current record is unavailable because either the reader is "
                + "at the beginning of the input and start() or advance() wasn't called, "
                + "or the last start() or advance() returned false.");
      }
      return currentKVPair;
    }

    @Override
    public Instant getCurrentTimestamp() throws NoSuchElementException {
      if (eventTime == null) {
        throw new NoSuchElementException(
            "Current timestamp is unavailable because either the reader is "
                + "at the beginning of the input and start() or advance() wasn't called, "
                + "or the last start() or advance() returned false.");
      }
      return eventTime;
    }

    @Override
    public boolean start() {
      currentOffset = this.startOffset;
      delay.delayStart(currentOffset);
      return advance();
    }

    @Override
    public boolean advance() {
      currentOffset++;

View on GitHub (pinned to 12126d8942)