UrlBuilder reuse with setEvent

Description

A single instance of UrlBuilder can not be reused multiple times if you set the event to different values with setEvent. I.e., the following test doesn't pass:

UrlBuilder urlBuilder = new UrlBuilder(Locale.getDefault(), "", false);
urlBuilder.setEvent("first");
assertEquals("?first=", urlBuilder.toString());
urlBuilder.setEvent("second");
assertEquals("?second=", urlBuilder.toString()); //Here, urlBuilder.toString() returns "?first="

The same pattern is at least partially supported with parameters because calling addParameter clears the cached toString() result (although there is no way of removing an added parameter).

The attached patch resolves the issue with a trivial change. There is no impact on existing "correct" code; if there's code in the wild that works on the assumption that calling setEvent() after a toString() does not actually change the event, that code will break.

Environment

None

Status

Assignee

BenB

Reporter

alessioc

Labels

None

Tester

None

Fix versions

Priority

Minor
Configure