[SPR-13537] UriComponentsBuilder interprets empty request parameters as null Created: 04/Oct/15 Updated: 12/Oct/15 Resolved: 12/Oct/15 Status: Project: Component/s: Affects Version/s: Fix Version/s: Resolved Spring Framework Web None Type: Reporter: Resolution: Labels: Remaining Estimate: Time Spent: Original Estimate: Bug Sam Brannen Works as Designed None Not Specified Issue Links: Relate relates to SPR-13524 HtmlUnitRequestBuilder doesn't handle... None Priority: Assignee: Votes: Minor Rossen Stoyanchev 0 Not Specified Not Specified Closed 16 weeks, 3 days ago Days since last comment: Last commented false by a User: Rossen Stoyanchev Last updater: Description Status Quo brought it to our attention that UriComponentsBuilder returns null for empty request parameters instead of an empty string. For example, given a request such as http://example.com/login?error, the error request parameter is empty but still present in the query string. Thus we would expect UriComponentsBuilder to store its value as an empty string; however, UriComponentsBuilder currently stores it in its query map as null. This is contrast to Spring MVC's support for @RequestParameter. When using @RequestParameter in a controller handler method, Spring always passes in an empty string for an empty request parameter value, regardless of whether the = sign is present in the query string. Analysis The source of this behavior is in UriComponentsBuilder.query(String), specifically in this line: queryParam(name, (value != null ? value : (StringUtils.hasLength(eq) ? "" : null))); For empty request parameter values, if the = sign is present, the value is set to an empty string ""; otherwise, the value is set to null. Furthermore, similar logic exists in UriComponentsBuilder.queryParam(String, Object...): queryParam(...) stores null instead of an empty string for an empty value. Deliverables 1. Ensure that UriComponentsBuilder stores empty request parameters as empty strings. Updated both query(String) and queryParam(String, Object...) See TODO in UriComponentsBuilderTests. Comments Comment by Rossen Stoyanchev [ 12/Oct/15 ] Resolving in favor of the existing behavior which preserves between empty value and value-less query parameters. It is conceivable that servers may have slightly different semantics for that. Note that the UriTemplateHandler introduced in 4.2 could be used to change this behavior where usage of the RestTemplate is concerned at least. Generated at Fri Feb 05 11:23:00 UTC 2016 using JIRA 6.4.11#64026sha1:78f6ec473a3f058bd5d6c30e9319c7ab376bdb9c.