apache/beam · error · NoSuchElementException

No current record (Indicates misuse. Perhaps advance() was…

Error message

No current record (Indicates misuse. Perhaps advance() was not called?)

What it means

KuduServiceImpl's reader Avantor/function getCurrent() returns the parsed current record; if advance() was never called (or the iterator is exhausted and getCurrent is invoked again), 'current' is null and a NoSuchElementException is thrown indicating API misuse of the reader.

Solutions

  1. Always call advance() first and only call getCurrent() after it returned true
  2. Stop iterating when advance() returns false instead of reading getCurrent() again
  3. Wrap reader consumption in the standard pattern: while (reader.advance()) { T item = reader.getCurrent(); ... }

Example fix

// before
T item = reader.getCurrent(); // NoSuchElementException
// after
if (reader.advance()) {
  T item = reader.getCurrent();
}
Defensive patterns

Strategy: type-guard

Validate before calling

boolean readable = reader.advance();
if (!readable) { return; } // nothing to read

Type guard

static <T> java.util.Optional<T> nextRecord(KuduServiceImpl.Reader<T> reader) {
  return reader.advance()
      ? java.util.Optional.of(reader.getCurrent())
      : java.util.Optional.empty();
}

Try / catch

try {
  T item = reader.getCurrent();
} catch (NoSuchElementException e) {
  // misuse: ensure advance() called and returned true before getCurrent()
}

Prevention

When it happens

Trigger: Calling getCurrent() on a KuduIO reader before any advance() call, or calling getCurrent() after advance() returned false (iterator exhausted).

Common situations: Custom Beam source consumers iterating a KuduSource reader incorrectly; wrapping the reader in code that assumes getCurrent() is valid without tracking advance()'s return value.

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/8152280ddb59dff8. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/kudu/src/main/java/org/apache/beam/sdk/io/kudu/KuduServiceImpl.java:179

        scanner = builder.build();
      }

      return advance();
    }

    /**
     * Returns the current record transformed into the desired type.
     *
     * @return the current record
     * @throws NoSuchElementException If the current does not exist
     */
    @Override
    public T getCurrent() throws NoSuchElementException {
      if (current != null) {
        return source.spec.getParseFn().apply(current);

      } else {
        throw new NoSuchElementException(
            "No current record (Indicates misuse. Perhaps advance() was not called?)");
      }
    }

    @Override
    public boolean advance() throws KuduException {
      // scanner pages over results, with each page holding an iterator of records
      if (iter == null || (!iter.hasNext() && scanner.hasMoreRows())) {
        iter = scanner.nextRows();
      }

      if (iter != null && iter.hasNext()) {
        current = iter.next();
        ++recordsReturned;
        return true;
      }

      return false;

View on GitHub (pinned to 12126d8942)