From 0b01182b8dc4aaaf7edba2bbf047b4594441ea35 Mon Sep 17 00:00:00 2001 From: Christoph Kutzinski Date: Sun, 22 May 2011 12:58:10 +0200 Subject: [PATCH] [FIXED JENKINS-9003] NPE when polling after node removed --- changelog.html | 3 +++ .../java/hudson/model/AbstractProject.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/changelog.html b/changelog.html index f2a4ea15d8..cc46c8079a 100644 --- a/changelog.html +++ b/changelog.html @@ -69,6 +69,9 @@ Upcoming changes
  • Catch FileNotFoundException in Maven builds if Mojos are executed from a classes directory. (issue 5044) +
  • + Fix NPE if node of last build isn't available anymore while polling for SCM changes. + (issue 9003 )
  • Set NODE_NAME for master node to "master" (issue 9671) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 715714cc01..cf01c0e9ea 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1263,7 +1263,7 @@ public abstract class AbstractProject

    ,R extends A // lock the workspace of the last build FilePath ws=lb.getWorkspace(); - if (ws==null || !ws.exists()) { + if (workspaceOffline(lb)) { // workspace offline. build now, or nothing will ever be built Label label = getAssignedLabel(); if (label != null && label.isSelfLabel()) { @@ -1326,6 +1326,24 @@ public abstract class AbstractProject

    ,R extends A return NO_CHANGES; } } + + private boolean workspaceOffline(R build) throws IOException, InterruptedException { + FilePath ws = build.getWorkspace(); + if (ws==null || !ws.exists()) { + return true; + } + + Node builtOn = build.getBuiltOn(); + if (builtOn == null) { // node built-on doesn't exist anymore + return true; + } + + if (builtOn.toComputer() == null) { // node still exists, but has 0 executors - o.s.l.t. + return true; + } + + return false; + } /** * Returns true if this user has made a commit to this project.