Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues
Collaborator

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

Activity

spring-projects-issues

spring-projects-issues commented on Jun 24, 2014

@spring-projects-issues
CollaboratorAuthor

Juergen Hoeller commented

George, which release have you been using this with before? Any idea when that regression was introduced?

Juergen

spring-projects-issues

spring-projects-issues commented on Jun 24, 2014

@spring-projects-issues
CollaboratorAuthor

George Shan Lyons commented

We were using Spring 3.1.2 previously. I am currently at work, but would be happy to help narrow this down further.

-Shan

spring-projects-issues

spring-projects-issues commented on Jun 24, 2014

@spring-projects-issues
CollaboratorAuthor

George Shan Lyons commented

Working in Spring 3.2.1.RELEASE. Broken in Spring 3.2.2.RELEASE.

spring-projects-issues

spring-projects-issues commented on Jun 25, 2014

@spring-projects-issues
CollaboratorAuthor

Juergen Hoeller commented

This seems to be a side effect of #14904... As we didn't have any tests for such multiple independent build() calls on the same builder instance, we unfortunately didn't notice.

Anyway, fixed for 4.1 now and to be backported to 4.0.6 and 3.2.10.

Juergen

spring-projects-issues

spring-projects-issues commented on Jun 25, 2014

@spring-projects-issues
CollaboratorAuthor

George Shan Lyons commented

Thank you very much!

added
status: backportedAn issue that has been backported to maintenance branches
in: webIssues in web modules (web, webmvc, webflux, websocket)
on Jan 11, 2019
added this to the 4.0.6 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @jhoeller@spring-projects-issues

      Issue actions

        URIComponentsBuilder shares state across calls of .build() [SPR-11885] · Issue #16504 · spring-projects/spring-framework