Skip to content

URIComponentsBuilder shares state across calls of .build() [SPR-11885] #16504

Closed
@spring-projects-issues

Description

@spring-projects-issues

George Shan Lyons opened SPR-11885 and commented

In previous versions, the following was possible:

final UriComponentsBuilder commonUri = UriComponentsBuilder.fromHttpUrl("http://thing.com").pathSegment("/somePath");
UriComponents url1 = commonUri.build();
UriComponents url2 = commonUri.pathSegment("additionalPath").build();

Unfortunately, the state is now internally shared, I believe through a List of PathComponentBuilders, such that the change to the builder in url2 affects url1. The expectation is that, once build is called, the UriComponents instance is no longer mutable through the builder.

Workaround is simple, just create 2 builders.


Affects: 3.2.8

Issue Links:

Referenced from: commits 247771c, d239016, c73ac07

Backported to: 3.2.10

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions