{"record":{"id":"8152280ddb59dff8","repo":"apache/beam","slug":"no-current-record-indicates-misuse-perhaps-advance-was-not","errorCode":null,"errorMessage":"No current record (Indicates misuse. Perhaps advance() was not called?)","messagePattern":"No current record \\(Indicates misuse\\. Perhaps advance\\(\\) was not called\\?\\)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/kudu/src/main/java/org/apache/beam/sdk/io/kudu/KuduServiceImpl.java","lineNumber":179,"sourceCode":"        scanner = builder.build();\n      }\n\n      return advance();\n    }\n\n    /**\n     * Returns the current record transformed into the desired type.\n     *\n     * @return the current record\n     * @throws NoSuchElementException If the current does not exist\n     */\n    @Override\n    public T getCurrent() throws NoSuchElementException {\n      if (current != null) {\n        return source.spec.getParseFn().apply(current);\n\n      } else {\n        throw new NoSuchElementException(\n            \"No current record (Indicates misuse. Perhaps advance() was not called?)\");\n      }\n    }\n\n    @Override\n    public boolean advance() throws KuduException {\n      // scanner pages over results, with each page holding an iterator of records\n      if (iter == null || (!iter.hasNext() && scanner.hasMoreRows())) {\n        iter = scanner.nextRows();\n      }\n\n      if (iter != null && iter.hasNext()) {\n        current = iter.next();\n        ++recordsReturned;\n        return true;\n      }\n\n      return false;","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/kudu/src/main/java/org/apache/beam/sdk/io/kudu/KuduServiceImpl.java#L161-L197","documentation":"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.","triggerScenarios":"Calling getCurrent() on a KuduIO reader before any advance() call, or calling getCurrent() after advance() returned false (iterator exhausted).","commonSituations":"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.","solutions":["Always call advance() first and only call getCurrent() after it returned true","Stop iterating when advance() returns false instead of reading getCurrent() again","Wrap reader consumption in the standard pattern: while (reader.advance()) { T item = reader.getCurrent(); ... }"],"exampleFix":"// before\nT item = reader.getCurrent(); // NoSuchElementException\n// after\nif (reader.advance()) {\n  T item = reader.getCurrent();\n}","handlingStrategy":"type-guard","validationCode":"boolean readable = reader.advance();\nif (!readable) { return; } // nothing to read","typeGuard":"static <T> java.util.Optional<T> nextRecord(KuduServiceImpl.Reader<T> reader) {\n  return reader.advance()\n      ? java.util.Optional.of(reader.getCurrent())\n      : java.util.Optional.empty();\n}","tryCatchPattern":"try {\n  T item = reader.getCurrent();\n} catch (NoSuchElementException e) {\n  // misuse: ensure advance() called and returned true before getCurrent()\n}","preventionTips":["Follow the standard iterator protocol: advance() then getCurrent()","Never call getCurrent() after advance() returned false","Encapsulate reader iteration in a helper method to enforce the protocol"],"tags":["java","apache-beam","kudu","iterator-misuse","nosuchelement"],"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"}