Skip to content

Commit

Permalink
Merge pull request #1109 from olivergondza/JENKINS-21474
Browse files Browse the repository at this point in the history
[JENKINS-21474] Fix NPE in View.getComputers()
  • Loading branch information
olivergondza committed Feb 1, 2014
2 parents 547a5f9 + e31f8dc commit 380dad9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/View.java
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions test/src/test/java/hudson/model/ViewTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 380dad9

Please sign in to comment.