-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[hotfix] Add null check for currentReader in pauseOrResumeSplits #27200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a null safety check to the pauseOrResumeSplits method in HybridSourceReader to prevent potential NullPointerException when the method is called before any source reader has been initialized.
- Adds null check before delegating to the current reader's
pauseOrResumeSplitsmethod
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void pauseOrResumeSplits( | ||
| Collection<String> splitsToPause, Collection<String> splitsToResume) { | ||
| currentReader.pauseOrResumeSplits(splitsToPause, splitsToResume); | ||
| if (currentReader != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is null, should we error?
Would it fail later if we do not error here ?
Can we get an empty collection here - that we could also check for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's normal for the currentReader to be null. I'm just not sure if this method will be invoked when it happens. So just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at the non test code, I see
flink/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
Line 767 in 0ffacdc
| pauseOrResumeSplits(splitsToPause, splitsToResume); |
flink/flink-runtime/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java
Line 727 in 0ffacdc
| pauseOrResumeSplits(Collections.singletonList(splitId), Collections.emptyList()); |
as the 2 callers that end up in this code - both of whom call this with a non null. I suggest we do not need the null check as this parameter is never null. Did I miss anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Actually we had used the version without the null check for several months internally and didn't hit any issues. It implies the null check could be redundant. However, potentially more code will use this method in the future. So adding the check would be a defensive measure (I actually forgot to push this commit to my previous PR). I'm fine with both.
What is the purpose of the change
Add null check for pauseOrResumeSplits to avoid NPE
Brief change log
Added null check for
currentReaderin pauseOrResumeSplits().Verifying this change
Please make sure both new and modified tests in this PR follow the conventions for tests defined in our code quality guide.
This change is a trivial rework / code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
@Public(Evolving): (yes / no)Documentation