[Java]Fix NPE in UnboundedSolaceReader.getWatermark during disconnection (fixes #32660) - #35919
[Java]Fix NPE in UnboundedSolaceReader.getWatermark during disconnection (fixes #32660) #35919Suvrat1629 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @Suvrat1629, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses and resolves a NullPointerException (NPE) that could occur in the UnboundedSolaceReader's getWatermark() method. The NPE was triggered specifically during disconnections from a Solace broker when the watermarkPolicy.getWatermark() call returned null. The fix ensures the pipeline's stability by introducing a null check and providing a safe fallback watermark, preventing crashes and allowing the system to gracefully handle temporary disconnections.
Highlights
- NullPointerException Fix: Implemented a null check for the
watermarkPolicy.getWatermark()method call withinUnboundedSolaceReader.getWatermark(). - Robustness Improvement: When
watermarkPolicy.getWatermark()returns null (indicating a likely disconnection), the method now returnsBoundedWindow.TIMESTAMP_MIN_VALUEto prevent pipeline failure and provide a safe fallback. - Logging: Added a warning log message when
watermarkPolicyreturns null to provide visibility into the fallback mechanism.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
Assigning reviewers: R: @kennknowles for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
| } | ||
| return watermarkPolicy.getWatermark(); | ||
| Instant watermark = watermarkPolicy.getWatermark(); | ||
| if (watermark == null) { |
There was a problem hiding this comment.
This value is forbidden from being null, so we shouldn't need the check. It is not marked @Nullable in the class WatermarkPolicy and null checking is enabled for that class so the type should be accurate.
Where is the null coming from?
There was a problem hiding this comment.
Oh well my pr was a follow up fix for my older pr that got closed due to inactivity(#34296), this is the fix I thought @Abacn had asked for and since I had gotten back to contributing I thought about putting some work into this :)
Also as you said that:
null checking is enabled for that class so the type should be accurate.
since I am trying to learn about the codebase could you tell me how this works.
Thank you.
There was a problem hiding this comment.
Oh well my pr was a follow up fix for my older pr that got closed due to inactivity(#34296), this is the fix I thought @Abacn had asked for and since I had gotten back to contributing I thought about putting some work into this :)
Thank you! Yes, I still think we should try to fix it. There is a null getting in somewhere that should be impossible, and we can track it down.
Also as you said that:
null checking is enabled for that class so the type should be accurate.
since I am trying to learn about the codebase could you tell me how this works.
Yes! We use checkerframework to modernize Java's type system. Any time you see a type Foo anywhere in the Beam codebase this means it is a non-null Foo. Only @Nullable Foo can be null.
But because we added this after the project was somewhat large, many classes have @SuppressWarnings("nullness") and that turns it off. But this is forbidden for new code. The SolaceIO connector is in good shape; it does not turn off the null checking.
So this null that violates the type system is probqably coming from one of the following places:
- an external library that returns null but is not annotated that it may return null,
- some part of the Beam codebase where null checking is disabled,
So the solution here is to figure out how we have a forbidden null. I read the javadoc on WatermarkPolicy.getWatermark() and it seems pretty clear that it should never return null. I clicked through some of the other methods that could end up leaking a null into it and they all were autovalue classes that also do not allow null, so I'm not sure!
There was a problem hiding this comment.
Oh thanks for the explanation I had suspected it to be checkerframework but I just wanted to be sure.
So this null that violates the type system is probqably coming from one of the following places:
an external library that returns null but is not annotated that it may return null,
some part of the Beam codebase where null checking is disabled,
Yeah probably, I'll see what I can come up with when I go through the code. Until then if you expect me to make any improvements to the pr then please tell me so.
Thank you.
There was a problem hiding this comment.
Responding to your top level comment here, since it is where there is work to do: this null check should be removed. It is forbidden by the type system. If you have a reproduction where a null shows up here, then that is the bug to address.
|
Reminder, please take a look at this pr: @kennknowles |
|
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @robertwb for label java. Available commands:
|
|
Reminder, please take a look at this pr: @robertwb |
|
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @ahmedabu98 for label java. Available commands:
|
|
Reminder, please take a look at this pr: @ahmedabu98 |
|
waiting on author |
|
@kennknowles Based on the comment tree can you tell me what I can do here? |
|
Reminder, please take a look at this pr: @ahmedabu98 |
|
Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment R: @chamikaramj for label java. Available commands:
|
|
Reminder, please take a look at this pr: @chamikaramj |
|
waiting on author |
|
npe was happening when code was as follows: Current implementation is different so I'm not sure if this PR and issue is relevant anymore. |
Please add a meaningful description for your change here
Fixes #32660
Fixed NPE in UnboundedSolaceReader.getWatermark during Solace broker disconnections by adding explicit null check for watermarkPolicy.getWatermark() and returning BoundedWindow.TIMESTAMP_MIN_VALUE as a safe fallback.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.