Repository navigation
Conversation
What: Href.with() now appends the new value to a copy of the key's value list, not to the list owned by the original Href. Why: the previous implementation added the value straight into the shared list, silently changing the query of the original Href when the key already existed (yegor256#1834), which violated the immutability contract of the class. How: we fetch the existing values with getOrDefault() into a fresh ArrayList, add the value to it, and put the copied list back into the map before building the new Href. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
This branch has not been deployed
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
Href.with()no longer mutates the value list of the originalHref. It copies the list of the given key into a freshArrayList, appends the value to the copy, and puts the copy back into the params map. Regression tests were added toHrefTest.Why
When the key already existed, the old implementation called
map.get(key).add(...)on the list shared with the original object, so the query of the original changed afterwith()— a violation of the immutability contract of the class. See #1834:How
The
containsKey/put/get().add()sequence inHref.with()is replaced with a singlegetOrDefault(..., Collections.emptyList())wrapped into a newArrayList, followed byvalues.add(...)andmap.put(...). Other value lists stay untouched.Four tests added: the original stays unchanged when the key exists or is fresh, the returned
Hrefcontains both values for an existing key, and the new parameter for a fresh one.Full gate passed locally:
mvn clean install -Pqulice.DCO: Signed-off-by: Inf1mum vadimlazuk5@gmail.com