Skip to content
Permalink
Browse files
Merge pull request #7 from christ66/ZD-23986
[FIXED JENKINS-26452] Prevent NPE if no publisher in conditional step.
  • Loading branch information
ikedam committed Jan 17, 2015
2 parents 02e403e + 6153aa1 commit 932c255cb1236e61efcb4c9549313ca3ec5f65b5
Showing 2 changed files with 40 additions and 1 deletion.
@@ -193,6 +193,17 @@ public Object readResolve() {
publisherList.add(publisher);
publisher = null;
}

if (publisherList != null) {
// We also need to guard against any null values in the publisherList
// This can happen if the projects publisher list was removed, returning
// a list with one null element.
if (publisherList.contains(null)) {
publisherList = new ArrayList<BuildStep>(publisherList);
publisherList.remove(null);
}
}

if (runner == null)
runner = new BuildStepRunner.Fail();
return this;
@@ -279,7 +290,9 @@ public ConditionalPublisher newInstance(StaplerRequest req, JSONObject formData)
if (a != null && !a.isEmpty()) {
publisherList = new ArrayList<BuildStep>(a.size());
for(int idx = 0; idx < a.size(); ++idx) {
publisherList.add(bindJSONWithDescriptor(req, a.getJSONObject(idx), "publisherList"));
BuildStep buildstep = bindJSONWithDescriptor(req, a.getJSONObject(idx), "publisherList");
if (buildstep != null)
publisherList.add(buildstep);
}
}
}
@@ -27,6 +27,7 @@
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import hudson.Launcher;
@@ -44,6 +45,7 @@
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.BuildTrigger;
import hudson.tasks.Mailer;
import hudson.tasks.Publisher;
import hudson.tasks.junit.TestDataPublisher;
import hudson.tasks.junit.TestResult;
import hudson.tasks.junit.TestResultAction.Data;
@@ -53,6 +55,7 @@
import org.jenkins_ci.plugins.run_condition.BuildStepRunner;
import org.jenkins_ci.plugins.run_condition.core.AlwaysRun;
import org.jenkins_ci.plugins.run_condition.core.NeverRun;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -87,6 +90,29 @@ public void testWithoutPublishers() throws Exception {
reconfigure(p);
}

@Bug(19985)
public void testNullCondition() throws Exception {
FreeStyleProject p = createFreeStyleProject();
ConditionalPublisher conditionalPublisher = new ConditionalPublisher(new AlwaysRun(),
Collections.<BuildStep>singletonList(null),
null,
false,
null,
null);
FlexiblePublisher fp = new FlexiblePublisher(Arrays.asList(conditionalPublisher));
p.getPublishersList().add(fp);
p.save();
jenkins.reload();

DescribableList<Publisher, Descriptor<Publisher>> publishersList = ((FreeStyleProject) jenkins.getItemByFullName(p.getFullName()))
.getPublishersList();
FlexiblePublisher publisher = publishersList.get(FlexiblePublisher.class);
List<ConditionalPublisher> publishers = publisher.getPublishers();
conditionalPublisher = publishers.get(0);
assertNotNull(conditionalPublisher.getPublisherList());
assertTrue(conditionalPublisher.getPublisherList().isEmpty());
}

public void testSingleCondition() throws Exception {
FreeStyleProject p = createFreeStyleProject();
BuildTrigger trigger = new BuildTrigger("anotherProject", Result.SUCCESS);

0 comments on commit 932c255

Please sign in to comment.