[FLINK-39873][streaming] Add null check for connectedSocket in SocketStreamIterator.notifyOfError()#28332
Open
jubins wants to merge 2 commits into
Open
[FLINK-39873][streaming] Add null check for connectedSocket in SocketStreamIterator.notifyOfError()#28332jubins wants to merge 2 commits into
connectedSocket in SocketStreamIterator.notifyOfError()#28332jubins wants to merge 2 commits into
Conversation
…StreamIterator.notifyOfError()
SocketStreamIterator.notifyOfError()connectedSocket in SocketStreamIterator.notifyOfError()
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Fixes FLINK-39873 — The
SocketStreamIterator.notifyOfError()method attempts to closeconnectedSocketwithout checking if it's null first, which can cause aNullPointerException.The
connectedSocketfield is only initialized during the first call toreadNextFromStream(). IfnotifyOfError()is called before any data is read (e.g., during early initialization errors),connectedSocketwill be null, causing aNullPointerException. While the exception is currently caught and ignored, this creates unnecessary exceptions and represents poor coding practice.This PR adds a null check before attempting to close
connectedSocket, aligning the error handling pattern with the existingclose()method in the same class.Brief change log
connectedSocketinSocketStreamIterator.notifyOfError()before callingclose()methodclose()method (line 114)SocketStreamIteratorTest:testNotifyOfErrorBeforeConnection()— verifies thatnotifyOfError()can be called safely beforeconnectedSocketis initializedtestNotifyOfErrorMultipleTimes()— ensures multiple error notifications are handled gracefully with the first error taking precedenceVerifying this change
This change is covered by two new unit tests in
SocketStreamIteratorTest:testNotifyOfErrorBeforeConnection()— Verifies that callingnotifyOfError()before any connection is established (i.e., whenconnectedSocketis null) does not throw aNullPointerExceptionand properly propagates the error tohasNext()testNotifyOfErrorMultipleTimes()— Validates that multiple calls tonotifyOfError()are handled correctly, with the first error taking precedence (as per the existing logic in the method)The fix follows the same defensive coding pattern already established in the
close()method within the same class, which properly checksif (connectedSocket != null)before attempting to close the socket.Does this pull request potentially affect one of the following parts
@Public(Evolving): no —SocketStreamIteratoris annotated with@ExperimentalDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Opus 4.8