gemini-code-assist[bot] commented on code in PR #37691:
URL: https://github.com/apache/beam/pull/37691#discussion_r2843409460


##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java:
##########
@@ -669,12 +675,23 @@ static class LazyBlockingStateFetchingIterator implements 
PrefetchableIterator<B
     private final StateRequest stateRequestForFirstChunk;
     private ByteString continuationToken;
     private CompletableFuture<StateResponse> prefetchedResponse;
+    private boolean hasNoState;
 
     LazyBlockingStateFetchingIterator(
         BeamFnStateClient beamFnStateClient, StateRequest 
stateRequestForFirstChunk) {
       this.beamFnStateClient = beamFnStateClient;
       this.stateRequestForFirstChunk = stateRequestForFirstChunk;
       this.continuationToken = 
stateRequestForFirstChunk.getGet().getContinuationToken();
+      this.hasNoState = false;
+    }
+
+    LazyBlockingStateFetchingIterator(
+      BeamFnStateClient beamFnStateClient, StateRequest 
stateRequestForFirstChunk,
+      boolean hasNoState) {
+      this.beamFnStateClient = beamFnStateClient;
+      this.stateRequestForFirstChunk = stateRequestForFirstChunk;
+      this.continuationToken = 
stateRequestForFirstChunk.getGet().getContinuationToken();
+      this.hasNoState = hasNoState;
     }

Review Comment:
   ![critical](https://www.gstatic.com/codereviewagent/critical.svg)
   
   If `hasNoState` is true, the `continuationToken` should be initialized to 
`null`. This ensures that `hasNext()` returns `false` and prevents `next()` 
from being called. Currently, if `hasNoState` is true, `continuationToken` is 
still initialized from the request, `hasNext()` returns `true`, and `next()` 
eventually throws a `NullPointerException` because `prefetchedResponse` is 
never initialized in `prefetch()`.
   
   ```suggestion
       LazyBlockingStateFetchingIterator(
         BeamFnStateClient beamFnStateClient, StateRequest 
stateRequestForFirstChunk,
         boolean hasNoState) {
         this.beamFnStateClient = beamFnStateClient;
         this.stateRequestForFirstChunk = stateRequestForFirstChunk;
         this.continuationToken =
             hasNoState ? null : 
stateRequestForFirstChunk.getGet().getContinuationToken();
         this.hasNoState = hasNoState;
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to