Skip to content
Permalink
Browse files

Merge pull request #1109 from olivergondza/JENKINS-21474

[JENKINS-21474] Fix NPE in View.getComputers()
  • Loading branch information
olivergondza committed Feb 1, 2014
2 parents 547a5f9 + e31f8dc commit 380dad924e5321c8346fb820912033dc9a7efa28
@@ -401,7 +401,7 @@ public void setConcurrentBuild(boolean b) throws IOException {
* If this project is configured to be always built on this node,
* return that {@link Node}. Otherwise null.
*/
public Label getAssignedLabel() {
public @CheckForNull Label getAssignedLabel() {
if(canRoam)
return null;

@@ -448,7 +448,7 @@ private boolean isRelevant(Collection<Label> labels, Computer computer) {
if (labels.contains(null) && node.getMode() == Mode.NORMAL) return true;

for (Label l : labels)
if (l.contains(node))
if (l != null && l.contains(node))
return true;
return false;
}
@@ -38,11 +38,13 @@
import hudson.matrix.LabelAxis;
import hudson.matrix.MatrixProject;
import hudson.model.Queue.Task;
import hudson.model.Node.Mode;

import org.jvnet.hudson.test.Email;
import org.w3c.dom.Text;

import static hudson.model.Messages.Hudson_ViewName;
import hudson.slaves.DumbSlave;
import hudson.util.HudsonIsLoading;
import java.io.File;
import java.io.IOException;
@@ -301,6 +303,27 @@ public void testGetComputers() throws IOException, Exception{
assertContainsNodes(view3, slave0, slave1, slave2, slave3, slave4);
}

@Test
@Bug(21474)
public void testGetComputersNPE() throws Exception {
ListView view = listView("aView");
view.filterExecutors = true;

DumbSlave dedicatedSlave = j.createOnlineSlave();
dedicatedSlave.setMode(Mode.EXCLUSIVE);
view.add(j.createFreeStyleProject());

FreeStyleProject tiedJob = j.createFreeStyleProject();
tiedJob.setAssignedNode(dedicatedSlave);
view.add(tiedJob);

DumbSlave notIncludedSlave = j.createOnlineSlave();
notIncludedSlave.setMode(Mode.EXCLUSIVE);

assertContainsNodes(view, j.jenkins, dedicatedSlave);
assertNotContainsNodes(view, notIncludedSlave);
}

private void assertContainsNodes(View view, Node... slaves) {
for (Node slave: slaves) {
assertTrue(

0 comments on commit 380dad9

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