Skip to content
Permalink
Browse files

Merge pull request #3028 from daniel-beck/JENKINS-45472

[JENKINS-45472] Copy the list in case it's reused elsewhere
  • Loading branch information
oleg-nenashev committed Oct 1, 2017
2 parents f2ac41e + 9c939c4 commit fbaa059cf0a842a107858cc39f8df5e8795858a7
@@ -100,7 +100,7 @@
private transient Run<?, ?> run;

public ParametersAction(List<ParameterValue> parameters) {
this.parameters = parameters;
this.parameters = new ArrayList<>(parameters);
String paramNames = SystemProperties.getString(SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME);
safeParameters = new TreeSet<>();
if (paramNames != null) {
@@ -2,6 +2,7 @@

import hudson.Functions;
import hudson.Launcher;
import hudson.model.queue.QueueTaskFuture;
import hudson.tasks.BatchFile;
import hudson.tasks.Builder;
import org.junit.Rule;
@@ -11,8 +12,10 @@
import org.jvnet.hudson.test.recipes.LocalData;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -283,6 +286,29 @@ public void nonParameterizedJobButWhitelisted() throws Exception {
}
}

@Test
@Issue("JENKINS-45472")
public void ensureNoListReuse() throws Exception {
FreeStyleProject p1 = j.createFreeStyleProject();
p1.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("foo", "")));
FreeStyleProject p2 = j.createFreeStyleProject();
p2.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("foo", "")));

List<ParameterValue> params = new ArrayList<>();
params.add(new StringParameterValue("foo", "for p1"));
p1.scheduleBuild2(1, new ParametersAction(params));
params.clear();
params.add(new StringParameterValue("foo", "for p2"));
p2.scheduleBuild2(0, new ParametersAction(params));

j.waitUntilNoActivity();

assertEquals(1, p1.getLastBuild().getAction(ParametersAction.class).getParameters().size());
assertEquals(1, p2.getLastBuild().getAction(ParametersAction.class).getParameters().size());
assertEquals(p1.getLastBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), "for p1");
assertEquals(p2.getLastBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), "for p2");
}

public static boolean hasParameterWithName(Iterable<ParameterValue> values, String name) {
for (ParameterValue v : values) {
if (v.getName().equals(name)) {

0 comments on commit fbaa059

Please sign in to comment.