Skip to content
Permalink
Browse files

[JENKINS-21474] Fix NPE in View.getComputers()

  • Loading branch information
olivergondza committed Jan 31, 2014
1 parent 3aa812f commit e31f8dc2d361990194cb559395c55866092b35cb
@@ -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 e31f8dc

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