-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Check hasNext when looking for ordered UserDestinationResult sessionIds #34333
base: main
Are you sure you want to change the base?
Check hasNext when looking for ordered UserDestinationResult sessionIds #34333
Conversation
Signed-off-by: Branden Clark <[email protected]>
@@ -280,7 +280,7 @@ public void send(UserDestinationResult destinationResult, Message<?> message) th | |||
Iterator<String> itr = (sessionIds != null ? sessionIds.iterator() : 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.
Interestingly, sessionIds coming from destinationResult.getSessionIds() is documented to be nullable, but actually the sessionIds are final and instantiated to always be non-null. That method could be annotated @nonnull and the logic here would be simpler. sessionIds doesn't have to be checked for null in this line, and therefore itr is never null and doesn't need to be check for null in line 283.
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.
Good point! I'll make that change just so it's up for viewing and we can get some feedback from @rstoyanchev.
Signed-off-by: Branden Clark <[email protected]>
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.
The proposed updates make sense. Thanks for the pull request.
As UserDestinationResult
is typically created by the framework, and we no longer use the pre-6.1 constructor, we should probably deprecate it. Could you clarify what or who is calling that constructor?
We have a custom I'm pretty novice in this space, but it seems like the pre-6.1 constructor is still useful when needing to customize the |
Found a bug in
UserDestinationMessageHandler.SendHelper#send
that occurs when theUserDestinationResult
was created by the pre-6.1.x constructor. Bug was introduced with 3277b0dIdeally this fix will target 6.1+ and should be compatible. Not sure if there's a special way to call that out as a first-time contributor.
Changes
Bug Details
The
UserDestinationMessageHandler
unsafely retrieves values from an iterator ofsessionId
strings to lookup ordered messages.This happens when the
UserDestinationResult
used to route the message was created with the pre-6.1.x constructor this retrieval throws aNoSuchElementException
.This is because the older constructor passes a
null
to the newer constructor for thesessionIds
constructor arg. The class attempts to safe handle thisnull
arg by creating an EmptySet that eventually provides an [EmptyIterator],(https://github.com/openjdk/jdk/blob/98a93e115137a305aed6b7dbf1d4a7d5906fe77c/src/java.base/share/classes/java/util/Collections.java#L4559) which then throws forSet#next
.This bug seems to only happen for custom implementations of
UserDestinationResolver
as theDefaultUserDestinationResolver
always provides a populated set to the new constructor.