Permalink
Browse files

[FIXED JENKINS-45909] ReverseBuildTrigger.upstreamProjects should be …

…null safe
  • Loading branch information...
abayer committed Aug 4, 2017
1 parent 7550d79 commit f8dd58425f54e27f5bf74a0bb769c50cbb96bc08
@@ -170,7 +170,7 @@ private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
}
@Override public void buildDependencyGraph(final AbstractProject downstream, DependencyGraph graph) {
for (AbstractProject upstream : Items.fromNameList(downstream.getParent(), upstreamProjects, AbstractProject.class)) {
for (AbstractProject upstream : Items.fromNameList(downstream.getParent(), Util.fixNull(upstreamProjects), AbstractProject.class)) {
graph.addDependency(new DependencyGraph.Dependency(upstream, downstream) {
@Override public boolean shouldTriggerBuild(AbstractBuild upstreamBuild, TaskListener listener, List<Action> actions) {
return shouldTrigger(upstreamBuild, listener);
@@ -253,7 +253,7 @@ synchronized void invalidateCache() {
continue;
}
List<Job> upstreams =
Items.fromNameList(downstream.getParent(), trigger.upstreamProjects, Job.class);
Items.fromNameList(downstream.getParent(), Util.fixNull(trigger.upstreamProjects), Job.class);
LOGGER.log(Level.FINE, "from {0} see upstreams {1}", new Object[]{downstream, upstreams});
for (Job upstream : upstreams) {
if (upstream instanceof AbstractProject && downstream instanceof AbstractProject) {
@@ -310,8 +310,8 @@ public void onLocationChanged(Item item, final String oldFullName, final String
ReverseBuildTrigger t = ParameterizedJobMixIn.getTrigger(p, ReverseBuildTrigger.class);
if (t != null) {
String revised =
Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName, t.upstreamProjects,
p.getParent());
Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName,
Util.fixNull(t.upstreamProjects), p.getParent());
if (!revised.equals(t.upstreamProjects)) {
t.upstreamProjects = revised;
try {
@@ -209,4 +209,19 @@ public void nullJobInTriggerNotCausesNPE() throws Exception {
assertThat("Build should be not triggered", downstreamJob1.getBuilds(), hasSize(0));
assertThat("Build should be triggered", downstreamJob2.getBuilds(), not(hasSize(0)));
}
@Issue("JENKINS-45909")
@Test
public void nullUpstreamProjectsNoNPE() throws Exception {
//job with trigger.upstreamProjects == null
final FreeStyleProject downstreamJob1 = r.createFreeStyleProject("downstream1");
ReverseBuildTrigger trigger = new ReverseBuildTrigger(null);
downstreamJob1.addTrigger(trigger);
downstreamJob1.save();
r.configRoundtrip(downstreamJob1);
// The reported issue was with Pipeline jobs, which calculate their dependency graphs via
// ReverseBuildTrigger.RunListenerImpl, so an additional test may be needed downstream.
trigger.buildDependencyGraph(downstreamJob1, Jenkins.getInstance().getDependencyGraph());
}
}

0 comments on commit f8dd584

Please sign in to comment.