-
Notifications
You must be signed in to change notification settings - Fork 38.5k
UriComponentsBuilder.uriComponents doesn't properly clone unmodifiable queryParams [SPR-17256] #21789
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
Comments
Ruslan Stelmachenko commented When I more think about this problem, I think maybe it is even better to fix This is how it look now: @Override
public void putAll(Map<? extends K, ? extends List<V>> map) {
this.targetMap.putAll(map);
} At now, when we call this method passing map where values are unmodifiable lists, this multimap becomes strange half-modifiable multimap:
Also, after calling this method, some underlying lists can be not So I think we should copy lists (values) of given map into new The same is true for Edit: Actually, the same also appies for After all, the use of That is just an IMHO, of course. The problem with |
Juergen Hoeller commented
|
Ruslan Stelmachenko commented The standard Map semantic is unaware of value types in the map. But For map - the I don't see any violation of contract if Still, such implementation of |
Juergen Hoeller commented Well, semantically a As you noted, this might be a breaking change for existing usage where specific |
Ruslan Stelmachenko commented I agree. Thanks you, Juergen. |
Also affects 4.3.24. |
Ruslan Stelmachenko opened SPR-17256 and commented
When
UriComponentsBuilder.uriComponents
clonesqueryParams
from givenUriComponents
, it leaves them as unmodifiableMultiValueMap
.This prevents to futher adding query params with the same name into the builder.
For example:
The
.queryParam("sort", "another_value")
line throws an exception on attempt to add another value to unmodifiableMultiValueMap
.While this code works:
The interested part of code to investigate this problem is:
org.springframework.web.util.HierarchicalUriComponents#copyToUriComponentsBuilder
Here is line
builder.queryParams(getQueryParams())
which sets the builder'squeryParams
to unmodifiableMultiValueMap
.I think we can clone unmodifiable queryParams here to be modifiable, or maybe better inside
org.springframework.web.util.UriComponentsBuilder#queryParams
methods to make this logic independent ofUriComponents
implementation.To make the intention more clear: this pattern of use
UriComponentsBuilder
is actually used inorg.springframework.web.util.DefaultUriBuilderFactory.DefaultUriBuilder#initUriComponentsBuilder
where I first faced this problem.It allows to set
baseUrl
and thenuriString
to concatenate them.So this code also throws an exception:
Affects: 5.0.8, 5.1 RC2
Issue Links:
Referenced from: commits 2820831, 1d58fac, c06b952
Backported to: 5.0.10
The text was updated successfully, but these errors were encountered: