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


##########
sdks/java/io/pulsar/src/main/java/org/apache/beam/sdk/io/pulsar/WriteToPulsarDoFn.java:
##########
@@ -53,6 +59,11 @@ public void processElement(@Element byte[] messageToSend) 
throws Exception {
     producer.send(messageToSend);
   }
 
+  @FinishBundle
+  public void finishBundle() throws PulsarClientException {
+    producer.close();
+  }
+
   @Teardown
   public void teardown() throws PulsarClientException {
     producer.close();

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   In `teardown()`, `producer.close()` is called. However, `producer` is 
initialized in `@StartBundle`. If the input `PCollection` is empty, 
`@StartBundle` is not invoked, `producer` remains `null`, and this call will 
result in a `NullPointerException`. It's safer to add a null check before 
closing the producer.
   
   ```java
       if (producer != null) {
         producer.close();
       }
   ```



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