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


##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/StreamingModeExecutionContext.java:
##########
@@ -893,9 +903,10 @@ public void setBacklogBytes(double backlogBytes) {
     }
 
     @Override
-    public <W extends BoundedWindow> TimerData getNextFiredTimer(Coder<W> 
windowCoder) {
-      if (cachedFiredSystemTimers == null) {
-        cachedFiredSystemTimers =
+    public <W extends BoundedWindow> @Nullable TimerData 
getNextFiredTimer(Coder<W> windowCoder) {
+      Iterator<TimerData> firedSystemTimers = cachedFiredSystemTimers;

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For stateless steps, `stateFamily` is `null`. To avoid unnecessary 
processing and potential `NullPointerException`s when filtering timers, we can 
return `null` immediately if `stateFamily` is `null`.
   
   ```java
       public <W extends BoundedWindow> @Nullable TimerData 
getNextFiredTimer(Coder<W> windowCoder) {
         if (stateFamily == null) {
           return null;
         }
         Iterator<TimerData> firedSystemTimers = cachedFiredSystemTimers;
   ```



##########
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/StreamingModeExecutionContext.java:
##########
@@ -950,12 +962,14 @@ private boolean isTimerUnmodified(TimerData timerData) {
       return updatedTimer == null || updatedTimer.equals(timerData);
     }
 
-    public <W extends BoundedWindow> TimerData getNextFiredUserTimer(Coder<W> 
windowCoder) {
-      if (cachedFiredUserTimers == null) {
+    public <W extends BoundedWindow> @Nullable TimerData getNextFiredUserTimer(
+        Coder<W> windowCoder) {
+      PeekingIterator<TimerData> firedUserTimers = cachedFiredUserTimers;

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Similar to `getNextFiredTimer`, we can return `null` immediately if 
`stateFamily` is `null` to avoid unnecessary processing and safely guarantee 
that `userTimerInternals` is non-null for subsequent operations.
   
   ```java
       public <W extends BoundedWindow> @Nullable TimerData 
getNextFiredUserTimer(
           Coder<W> windowCoder) {
         if (stateFamily == null) {
           return null;
         }
         PeekingIterator<TimerData> firedUserTimers = cachedFiredUserTimers;
   ```



-- 
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