-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Correctly handle null
listener in RedisMessageListenerContainer.remove(…)
#3009
Closed
sujl95
wants to merge
1
commit into
spring-projects:main
from
sujl95:fix/redis-message-listener-container-remove
Closed
Correctly handle null
listener in RedisMessageListenerContainer.remove(…)
#3009
sujl95
wants to merge
1
commit into
spring-projects:main
from
sujl95:fix/redis-message-listener-container-remove
Conversation
This file contains 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
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged
label
Sep 29, 2024
Care to attach a stack trace of your NPE? |
mp911de
added
type: bug
A general bug
and removed
status: waiting-for-triage
An issue we've not yet triaged
labels
Oct 1, 2024
mp911de
changed the title
Update RedisMessageListenerContainer.remove() to handle null listeners gracefully.
Correctly handle Oct 10, 2024
null
listener in RedisMessageListenerContainer.remove(…)
mp911de
added a commit
that referenced
this pull request
Oct 10, 2024
Simplify code and tests. See #3009
mp911de
added a commit
that referenced
this pull request
Oct 10, 2024
Simplify code and tests. See #3009
mp911de
added a commit
that referenced
this pull request
Oct 10, 2024
Simplify code and tests. See #3009
Thank you for your contribution. That's merged, polished, and backported now. |
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.
Hello,
While using the remove API, I encountered a NullPointerException (NPE) when the listener parameter was null. This PR addresses that issue by updating the remove method in RedisMessageListenerContainer.
The proposed changes ensure that when the listener is null, all listeners associated with the specified topic are removed. Additionally, the listenerTopics and mapping collections are cleaned up properly to prevent NPEs, making the listener removal process more robust.
If this contribution does not meet any of the project’s contribution requirements, please feel free to let me know, and I’ll be happy to make any necessary adjustments.
Summary:
This PR improves the
remove()
method inRedisMessageListenerContainer
by ensuring that it gracefully handlesnull
listeners. When thelistener
parameter isnull
, the method will now remove all associated listeners for the specified topic. The method has been updated to prevent NullPointerExceptions (NPEs) and ensure proper cleanup of thelistenerTopics
andmapping
collections.Description of the problem:
In the current implementation of
RedisMessageListenerContainer.remove()
, a potential NullPointerException (NPE) can occur when thelistener
parameter isnull
. This leads to unexpected behavior when trying to remove listeners for a specific topic, especially when no listeners are associated with the topic, or thelistener
isnull
.Without proper handling, the method can attempt to remove a
null
listener or update thelistenerTopics
andmapping
in a way that results in an NPE, disrupting the listener removal process.Proposed solution:
This PR updates the
remove()
method inRedisMessageListenerContainer
to correctly handle cases where thelistener
parameter isnull
. Specifically:listener
isnull
, all listeners associated with the specified topic are removed.listenerTopics
andmapping
collections are updated correctly by checking if collections are empty before removal.CollectionUtils.isEmpty()
is used to ensure proper cleanup of empty collections and avoid NPEs.These changes ensure that the listener removal process is more robust and handles edge cases involving
null
listeners and empty mappings more gracefully.Changes:
remove()
method inRedisMessageListenerContainer
to:listener
parameter isnull
.listenerTopics
andmapping
accordingly.CollectionUtils.isEmpty()
for safer collection handling.How to reproduce the issue:
The issue can be triggered by calling the
remove()
method with anull
listener while there are no listeners associated with the topic inlistenerTopics
. This would result in an NPE when trying to update the collections.Testing:
listener
isnull
.