Skip to content

Commit

Permalink
Merge pull request #3028 from daniel-beck/JENKINS-45472
Browse files Browse the repository at this point in the history
[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 fbaa059
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/ParametersAction.java
Expand Up @@ -100,7 +100,7 @@ public class ParametersAction implements RunAction2, Iterable<ParameterValue>, Q
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) {
Expand Down
26 changes: 26 additions & 0 deletions test/src/test/java/hudson/model/ParametersAction2Test.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit fbaa059

Please sign in to comment.