{"record":{"id":"eb44eae5a0d50e25","repo":"apache/beam","slug":"current-record-is-unavailable-because-either-the-reader-is","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/synthetic/src/main/java/org/apache/beam/sdk/io/synthetic/SyntheticUnboundedSource.java","lineNumber":157,"sourceCode":"\n    public SyntheticUnboundedReader(SyntheticUnboundedSource source, long startOffset) {\n      this.currentKVPair = null;\n      this.delay = new ReaderDelay(sourceOptions);\n      this.source = source;\n      this.currentOffset = 0;\n      this.startOffset = startOffset;\n      this.syntheticWatermark = new SyntheticWatermark(sourceOptions, source.endOffset);\n    }\n\n    @Override\n    public SyntheticUnboundedSource getCurrentSource() {\n      return source;\n    }\n\n    @Override\n    public KV<byte[], byte[]> getCurrent() throws NoSuchElementException {\n      if (currentKVPair == null) {\n        throw new NoSuchElementException(\n            \"Current record is unavailable because either the reader is \"\n                + \"at the beginning of the input and start() or advance() wasn't called, \"\n                + \"or the last start() or advance() returned false.\");\n      }\n      return currentKVPair;\n    }\n\n    @Override\n    public Instant getCurrentTimestamp() throws NoSuchElementException {\n      if (eventTime == null) {\n        throw new NoSuchElementException(\n            \"Current timestamp is unavailable because either the reader is \"\n                + \"at the beginning of the input and start() or advance() wasn't called, \"\n                + \"or the last start() or advance() returned false.\");\n      }\n      return eventTime;\n    }\n","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/synthetic/src/main/java/org/apache/beam/sdk/io/synthetic/SyntheticUnboundedSource.java#L139-L175","documentation":"SyntheticUnboundedSource's UnboundedReader.getCurrent() throws NoSuchElementException when no current record exists — i.e., start()/advance() has not yet been called successfully or the reader was not positioned. The synthetic unbounded source generates records continuously for streaming tests, and getCurrent() must only be read while positioned at an element.","triggerScenarios":"Calling getCurrent() on a freshly created UnboundedReader before start(); or after advance() returned false / start() returned false. Also occurs in custom runner code reading the synthetic source out of protocol order.","commonSituations":"Streaming test harnesses (e.g., perf tests, TestStream-like setups) driving UnboundedReaders manually; runner bugs where watermark advancement is attempted before the reader is started on an empty or just-created reader.","solutions":["Call start() once after createReader(), then check its boolean before reading getCurrent().","Only call getCurrent() after a successful start() or when advance() returned true.","Treat a false start()/advance() as end-of-data (for unbounded sources, an unusual condition) and stop reading."],"exampleFix":"// before\nUnboundedSource.UnboundedReader<KV<byte[], byte[]>> r = source.createReader(o, null);\nKV<byte[], byte[]> kv = r.getCurrent();\n// after\nUnboundedSource.UnboundedReader<KV<byte[], byte[]>> r = source.createReader(o, null);\nif (r.start()) {\n  KV<byte[], byte[]> kv = r.getCurrent();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean positioned(UnboundedSource.UnboundedReader<?> r) { try { r.getCurrent(); return true; } catch (NoSuchElementException e) { return false; } }","tryCatchPattern":"try {\n  KV<byte[], byte[]> kv = reader.getCurrent();\n} catch (NoSuchElementException e) {\n  // not started or exhausted — ensure start()/advance() contract is honored\n}","preventionTips":["Call start() once after createReader() before any getCurrent().","Check advance()'s return value each iteration.","Never cache/defer getCurrent() results across start()/advance() boundaries."],"tags":["apache-beam","java","source-reader","synthetic-source","streaming"],"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"}