Skip to content
Permalink
Browse files

[Fix JENKINS-46161] Make ReverseBuildTrigger#getUpstreamProjects null…

…-safe
  • Loading branch information...
liketic committed Sep 5, 2017
1 parent 5b8ea4f commit d2ae25cc06e5d7595acf7215513fc26bb096f181
@@ -110,7 +110,7 @@ public ReverseBuildTrigger(String upstreamProjects) {
}

public String getUpstreamProjects() {
return upstreamProjects;
return Util.fixNull(upstreamProjects);
}

public Result getThreshold() {
@@ -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(), Util.fixNull(upstreamProjects), AbstractProject.class)) {
for (AbstractProject upstream : Items.fromNameList(downstream.getParent(), getUpstreamProjects(), 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(), Util.fixNull(trigger.upstreamProjects), Job.class);
Items.fromNameList(downstream.getParent(), trigger.getUpstreamProjects(), 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) {
@@ -311,7 +311,7 @@ public void onLocationChanged(Item item, final String oldFullName, final String
if (t != null) {
String revised =
Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName,
Util.fixNull(t.upstreamProjects), p.getParent());
t.getUpstreamProjects(), p.getParent());
if (!revised.equals(t.upstreamProjects)) {
t.upstreamProjects = revised;
try {
@@ -224,4 +224,20 @@ public void nullUpstreamProjectsNoNPE() throws Exception {
// ReverseBuildTrigger.RunListenerImpl, so an additional test may be needed downstream.
trigger.buildDependencyGraph(downstreamJob1, Jenkins.getInstance().getDependencyGraph());
}

@Issue("JENKINS-46161")
@Test
public void testGetUpstreamProjectsShouldNullSafe() throws Exception {
ReverseBuildTrigger trigger1 = new ReverseBuildTrigger(null);
String upstream1 = trigger1.getUpstreamProjects();
assertEquals("", upstream1);

ReverseBuildTrigger trigger2 = new ReverseBuildTrigger("upstream");
String upstream2 = trigger2.getUpstreamProjects();
assertEquals("upstream", upstream2);

ReverseBuildTrigger trigger3 = new ReverseBuildTrigger("");
String upstream3 = trigger3.getUpstreamProjects();
assertEquals("", upstream3);
}
}

0 comments on commit d2ae25c

Please sign in to comment.
You can’t perform that action at this time.