-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
@lpfeup
Description
the addQueryParams/setQueryParams methods are assigning the passed argument directly to the class field queryParams. This has unwanted side-effects.
Code:
RequestBuilderBase.addQueryParams
RequestBuilderBase.setQueryParams
Example:
List<Param> params = new ArrayList<>(); params.add(new Param("testKey", "testVal")); Request request = httpClient.prepareGet(url) .setQueryParams(params) .addQueryParam("testKey2", "testVal2") // params list is modified here .build(); params.forEach(p -> System.out.println(p.getName() + ": " + p.getValue())); // EXPECTED: // testKey: testVal // OUTPUT: // testKey: testVal // testKey2: testVal2
Another example:
// params as unmodifiable collection List<Param> params = Collections.singletonList(new Param("testKey", "testVal")); Request request = httpClient.prepareGet(url) .setQueryParams(params) .addQueryParam("testKey2", "testVal2") .build(); // throws java.lang.UnsupportedOperationException on addQueryParam("testKey2", "testVal2")
I suggest replacing the assignments queryParams = params with copies as below:
queryParams = new ArrayList<>(params);
Would you be willing to accept a pull request?