{"record":{"id":"58725dfc05bd8377","repo":"apache/beam","slug":"current-element-is-null","errorCode":null,"errorMessage":"Current element is null","messagePattern":"Current element is null","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hcatalog/src/main/java/org/apache/beam/sdk/io/hcatalog/HCatalogIO.java","lineNumber":457,"sourceCode":"      public boolean advance() {\n        if (hcatIterator.hasNext()) {\n          current = hcatIterator.next();\n          return true;\n        } else {\n          current = null;\n          return false;\n        }\n      }\n\n      @Override\n      public BoundedHCatalogSource getCurrentSource() {\n        return source;\n      }\n\n      @Override\n      public HCatRecord getCurrent() {\n        if (current == null) {\n          throw new NoSuchElementException(\"Current element is null\");\n        }\n        return current;\n      }\n\n      @Override\n      public void close() {\n        // nothing to close/release\n      }\n    }\n  }\n\n  /** A {@link PTransform} to write to a HCatalog managed source. */\n  @AutoValue\n  public abstract static class Write extends PTransform<PCollection<HCatRecord>, PDone> {\n\n    abstract @Nullable Map<String, String> getConfigProperties();\n\n    abstract @Nullable String getDatabase();","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hcatalog/src/main/java/org/apache/beam/sdk/io/hcatalog/HCatalogIO.java#L439-L475","documentation":"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.","triggerScenarios":"Calling getCurrent() without a preceding successful advance(); calling getCurrent() after advance() returned false (end of partition); re-reading getCurrent() after the reader was closed.","commonSituations":"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.","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"],"exampleFix":"// before\nHCatRecord r = reader.getCurrent();\n// after\nif (reader.advance()) {\n  HCatRecord r = reader.getCurrent();\n}","handlingStrategy":"type-guard","validationCode":"if (reader.advance()) { HCatRecord r = reader.getCurrent(); } else { /* exhausted */ }","typeGuard":"boolean hasNext = reader.advance(); // gate on this before getCurrent()","tryCatchPattern":"try { HCatRecord r = reader.getCurrent(); } catch (NoSuchElementException e) { log.warn(\"getCurrent without advance\", e); return; }","preventionTips":["Always pair advance()/getCurrent()","Use Beam's standard AvroFn-style reader loops","Handle zero-record splits gracefully","Never call getCurrent() after close()"],"tags":["java","iterator","beam","hcatalog"],"backgroundTag":"invalid-state-transition","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}