提交 380dad92 编写于 作者: O Oliver Gondža

Merge pull request #1109 from olivergondza/JENKINS-21474

[JENKINS-21474] Fix NPE in View.getComputers()
...@@ -401,7 +401,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -401,7 +401,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* If this project is configured to be always built on this node, * If this project is configured to be always built on this node,
* return that {@link Node}. Otherwise null. * return that {@link Node}. Otherwise null.
*/ */
public Label getAssignedLabel() { public @CheckForNull Label getAssignedLabel() {
if(canRoam) if(canRoam)
return null; return null;
......
...@@ -448,7 +448,7 @@ public abstract class View extends AbstractModelObject implements AccessControll ...@@ -448,7 +448,7 @@ public abstract class View extends AbstractModelObject implements AccessControll
if (labels.contains(null) && node.getMode() == Mode.NORMAL) return true; if (labels.contains(null) && node.getMode() == Mode.NORMAL) return true;
for (Label l : labels) for (Label l : labels)
if (l.contains(node)) if (l != null && l.contains(node))
return true; return true;
return false; return false;
} }
......
...@@ -38,11 +38,13 @@ import hudson.matrix.AxisList; ...@@ -38,11 +38,13 @@ import hudson.matrix.AxisList;
import hudson.matrix.LabelAxis; import hudson.matrix.LabelAxis;
import hudson.matrix.MatrixProject; import hudson.matrix.MatrixProject;
import hudson.model.Queue.Task; import hudson.model.Queue.Task;
import hudson.model.Node.Mode;
import org.jvnet.hudson.test.Email; import org.jvnet.hudson.test.Email;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import static hudson.model.Messages.Hudson_ViewName; import static hudson.model.Messages.Hudson_ViewName;
import hudson.slaves.DumbSlave;
import hudson.util.HudsonIsLoading; import hudson.util.HudsonIsLoading;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -301,6 +303,27 @@ public class ViewTest { ...@@ -301,6 +303,27 @@ public class ViewTest {
assertContainsNodes(view3, slave0, slave1, slave2, slave3, slave4); 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) { private void assertContainsNodes(View view, Node... slaves) {
for (Node slave: slaves) { for (Node slave: slaves) {
assertTrue( assertTrue(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册