apache/beam · error · NoSuchElementException
Current element is null
Error message
Current element is null
What it means
HCatalogIO's HCatRecordReader throws NoSuchElementException from getCurrent() when getCurrent is called before the first element has been read via advance(), or after the iterator is exhausted. The library uses this to enforce the Avro/Beam reader contract: getCurrent() must only be called when a current record exists. It signals misuse of the reader lifecycle rather than a data problem.
Solutions
- Always call advance() and only call getCurrent() when it returned true
- Wrap reader usage in a standard while(reader.advance()){ record=reader.getCurrent(); } loop
- Check for empty partitions/splits before creating readers
- Log/inspect split boundaries if records appear to be missing
Example fix
// before
HCatRecord r = reader.getCurrent();
// after
if (reader.advance()) {
HCatRecord r = reader.getCurrent();
} Defensive patterns
Strategy: type-guard
Validate before calling
if (reader.advance()) { HCatRecord r = reader.getCurrent(); } else { /* exhausted */ } Type guard
boolean hasNext = reader.advance(); // gate on this before getCurrent()
Try / catch
try { HCatRecord r = reader.getCurrent(); } catch (NoSuchElementException e) { log.warn("getCurrent without advance", e); return; } Prevention
- Always pair advance()/getCurrent()
- Use Beam's standard AvroFn-style reader loops
- Handle zero-record splits gracefully
- Never call getCurrent() after close()
When it happens
Trigger: Calling getCurrent() without a preceding successful advance(); calling getCurrent() after advance() returned false (end of partition); re-reading getCurrent() after the reader was closed.
Common situations: Custom Beam DoFns that forget the advance() gate; misimplemented readers wrapping HCatRecordReader assuming getCurrent() behaves like a nullable peek; iterating a partitioned HCatalog table where a split yields zero records.
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
- A list of URNs for overriding transforms was provided but…
- A cannot be expanded
- A transform cannot be initiated using the provided config…
- AVRO schema doesn't match row schema. Row schema
- BigQuery data contained value
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/58725dfc05bd8377.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/io/hcatalog/src/main/java/org/apache/beam/sdk/io/hcatalog/HCatalogIO.java:457
public boolean advance() {
if (hcatIterator.hasNext()) {
current = hcatIterator.next();
return true;
} else {
current = null;
return false;
}
}
@Override
public BoundedHCatalogSource getCurrentSource() {
return source;
}
@Override
public HCatRecord getCurrent() {
if (current == null) {
throw new NoSuchElementException("Current element is null");
}
return current;
}
@Override
public void close() {
// nothing to close/release
}
}
}
/** A {@link PTransform} to write to a HCatalog managed source. */
@AutoValue
public abstract static class Write extends PTransform<PCollection<HCatRecord>, PDone> {
abstract @Nullable Map<String, String> getConfigProperties();
abstract @Nullable String getDatabase();View on GitHub (pinned to 12126d8942)