{"record":{"id":"633ba0ecf2329c07","repo":"apache/beam","slug":"no-block-has-been-successfully-read-from-getcurrentsource","errorCode":null,"errorMessage":"No block has been successfully read from \" + getCurrentSource()","messagePattern":"No block has been successfully read from \" \\+ getCurrentSource\\(\\)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/BlockBasedSource.java","lineNumber":181,"sourceCode":"     *\n     * <p>This method and {@link Block#getFractionOfBlockConsumed} are used to provide an estimate\n     * of progress within a block ({@code getCurrentBlock().getFractionOfBlockConsumed() *\n     * getCurrentBlockSize()}). It is acceptable for the result of this computation to be {@code 0},\n     * but progress estimation will be inaccurate.\n     */\n    public abstract long getCurrentBlockSize();\n\n    /**\n     * Returns the largest offset such that starting to read from that offset includes the current\n     * block.\n     */\n    public abstract long getCurrentBlockOffset();\n\n    @Override\n    public final T getCurrent() throws NoSuchElementException {\n      Block<T> currentBlock = getCurrentBlock();\n      if (currentBlock == null) {\n        throw new NoSuchElementException(\n            \"No block has been successfully read from \" + getCurrentSource());\n      }\n      return currentBlock.getCurrentRecord();\n    }\n\n    /**\n     * Returns true if the reader is at a split point. A {@code BlockBasedReader} is at a split\n     * point if the current record is the first record in a block. In other words, split points are\n     * block boundaries.\n     */\n    @Override\n    public boolean isAtSplitPoint() {\n      return atSplitPoint;\n    }\n\n    /**\n     * Reads the next record from the {@link #getCurrentBlock() current block} if possible. Will\n     * call {@link #readNextBlock()} to advance to the next block if not.","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/BlockBasedSource.java#L163-L199","documentation":"BlockBasedSource.BlockBasedReader.getCurrent() returns the current record of the current block; if no block has been successfully read yet (getCurrentBlock() returns null) there is no record to return, so it throws NoSuchElementException per the BoundedSource.Reader contract.","triggerScenarios":"Calling reader.getCurrent() before the first successful read (before start()/advance() populated the current block), or after a failed initial read.","commonSituations":"Custom source code inspecting getCurrent() immediately after reader creation; runner code probing current values before initiating reads; first-block read failures leaving the reader unpositioned.","solutions":["Call reader.start() and check its return value before accessing getCurrent()","Only read getCurrent() when the previous start()/readNextBlock()/advance() returned true","Guard with getCurrentBlock() != null before calling getCurrent()","Ensure the reader was properly prepared/initialized by the runner before use"],"exampleFix":"// before\nT value = reader.getCurrent();\n// after\nif (reader.start()) {\n  T value = reader.getCurrent();\n}","handlingStrategy":"type-guard","validationCode":"if (reader.getCurrentBlock() == null) {\n  throw new IllegalStateException(\"call start() before getCurrent()\");\n}","typeGuard":"static <T> boolean hasCurrent(BlockBasedSource.BlockBasedReader<T> r) {\n  return r.getCurrentBlock() != null;\n}","tryCatchPattern":"try {\n  T v = reader.getCurrent();\n} catch (NoSuchElementException e) {\n  // reader not started or exhausted\n}","preventionTips":["Always call start() and check its boolean before reading getCurrent()","Track reader state (started/finished) explicitly","Treat getCurrent() as valid only after a successful read step"],"tags":["java","io","reader","no-such-element"],"backgroundTag":"empty-result-set","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}