{"record":{"id":"3e657f0220f5dfaf","repo":"apache/beam","slug":"current-timestamp-is-unavailable-because-either-the-reader","errorCode":null,"errorMessage":"Current timestamp 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 timestamp 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":168,"sourceCode":"    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\n    @Override\n    public boolean start() {\n      currentOffset = this.startOffset;\n      delay.delayStart(currentOffset);\n      return advance();\n    }\n\n    @Override\n    public boolean advance() {\n      currentOffset++;\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/synthetic/src/main/java/org/apache/beam/sdk/io/synthetic/SyntheticUnboundedSource.java#L150-L186","documentation":"SyntheticUnboundedSource's reader.getCurrentTimestamp() throws NoSuchElementException when the eventTime field is null, meaning the reader is not positioned at a record: start()/advance() was never called successfully, or the last call returned false. Per the Beam reader contract, timestamps are only available alongside a current element.","triggerScenarios":"Calling getCurrentTimestamp() before start() succeeds or after advance() returns false; or calling it without a current element when the synthetic source's event-time configuration left eventTime unset.","commonSituations":"Custom runner or test code that requests the element's timestamp out of order; synthetic options that produce records without event time combined with timestamp-reading harness code.","solutions":["Ensure start() was called and returned true (or the last advance() returned true) before calling getCurrentTimestamp().","Guard the read: only ask for the timestamp immediately after obtaining a current element via getCurrent().","Verify synthetic source options configure event time if your harness requires timestamps."],"exampleFix":"// before\nInstant ts = reader.getCurrentTimestamp();\n// after\nif (reader.start()) {\n  Instant ts = reader.getCurrentTimestamp();\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"boolean hasTimestamp(UnboundedSource.UnboundedReader<?> r) { try { r.getCurrentTimestamp(); return true; } catch (NoSuchElementException e) { return false; } }","tryCatchPattern":"try {\n  Instant ts = reader.getCurrentTimestamp();\n} catch (NoSuchElementException e) {\n  // no current element: position reader via start()/advance() first\n}","preventionTips":["Only read timestamps immediately after a successful start()/advance().","Configure event time in synthetic options if your harness needs timestamps.","Wrap reader access in a helper enforcing the read protocol."],"tags":["apache-beam","java","source-reader","synthetic-source","timestamps"],"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"}