Skip to content

[Java]Fix NPE in UnboundedSolaceReader.getWatermark during disconnection (fixes #32660) - #35919

Closed
Suvrat1629 wants to merge 2 commits into
apache:masterfrom
Suvrat1629:solace-npe-fix
Closed

[Java]Fix NPE in UnboundedSolaceReader.getWatermark during disconnection (fixes #32660) #35919
Suvrat1629 wants to merge 2 commits into
apache:masterfrom
Suvrat1629:solace-npe-fix

Conversation

@Suvrat1629

Copy link
Copy Markdown
Contributor

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:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 within UnboundedSolaceReader.getWatermark().
  • Robustness Improvement: When watermarkPolicy.getWatermark() returns null (indicating a likely disconnection), the method now returns BoundedWindow.TIMESTAMP_MIN_VALUE to prevent pipeline failure and provide a safe fallback.
  • Logging: Added a warning log message when watermarkPolicy returns 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

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

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @kennknowles for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

}
return watermarkPolicy.getWatermark();
Instant watermark = watermarkPolicy.getWatermark();
if (watermark == null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @kennknowles

@github-actions

github-actions Bot commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @robertwb for label java.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @robertwb

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @ahmedabu98 for label java.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @ahmedabu98

@kennknowles

Copy link
Copy Markdown
Member

waiting on author

@Suvrat1629

Copy link
Copy Markdown
Contributor Author

@kennknowles Based on the comment tree can you tell me what I can do here?

@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @ahmedabu98

@github-actions

github-actions Bot commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @chamikaramj for label java.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @chamikaramj

@tvalentyn

Copy link
Copy Markdown
Contributor

waiting on author

@stankiewicz

Copy link
Copy Markdown
Contributor

npe was happening when code was as follows:

  @Override
  public Instant getWatermark() {
    // should be only used by a test receiver
    if (checkNotNull(sessionService).getReceiver().isEOF()) {
      return BoundedWindow.TIMESTAMP_MAX_VALUE;
    }
    return watermarkPolicy.getWatermark();

Current implementation is different so I'm not sure if this PR and issue is relevant anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: NPE in SolaceIO getWatermark

4 participants