Check hasNext when looking for ordered UserDestinationResult sessionIds #34333
+24
−5
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.
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.