Drop trailing empty token from splitByWholeSeparator#1710
Open
alhudz wants to merge 2 commits into
Open
Conversation
garydgregory
requested changes
Jun 16, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
@alhudz
Please see my comment.
| assertEquals(splitWithMultipleSeparatorExpectedResults[i], splitWithMultipleSeparator[i]); | ||
| } | ||
|
|
||
| // a trailing separator must not leak an empty token (it is dropped, like leading and adjacent ones) |
Member
There was a problem hiding this comment.
Please add a new @ParameterizedTest method for these new assertions.
Contributor
Author
There was a problem hiding this comment.
Done. Moved them into a new @ParameterizedTest, testSplitByWholeStringDropsTrailingEmpty, driven by @CsvSource. Each row also asserts the preserve-all-tokens variant still keeps the trailing empty token. Confirmed it fails on every row without the worker guard.
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.
Repro:
StringUtils.splitByWholeSeparator("a:b:", ":")returns["a", "b", ""]; expected["a", "b"]. The siblingStringUtils.split("a:b:", ":")already returns["a", "b"].Cause: in
splitByWholeSeparatorWorkerthe no-more-separator branch addsstr.substring(beg)unconditionally. When the input ends on a separator,beg == len, so an empty trailing token is appended. Leading and adjacent separators are already collapsed in non-preserve mode, so only the trailing case leaked, which disagrees with the documented "adjacent separators are treated as one separator".Fix: in non-preserve mode only add the trailing token when it is non-empty (
beg < len).splitByWholeSeparatorPreserveAllTokenskeeps the trailing empty token as before.mvn; that'smvnon the command line by itself.