Skip to content
Permalink
Browse files
[FIXED JENKINS-23277] Better diagnosis for an NPE probably involving …
…cloud slaves.

(cherry picked from commit 3f8fc4e)
  • Loading branch information
jglick authored and olivergondza committed Jul 2, 2014
1 parent b6b94ea commit eedf51eae4720d6eae05d8821e64bd37ab72c092
Showing with 17 additions and 5 deletions.
  1. +13 −2 core/src/main/java/hudson/model/AbstractBuild.java
  2. +4 −3 core/src/main/java/hudson/model/Executor.java
@@ -87,6 +87,7 @@
import org.kohsuke.stapler.interceptor.RequirePOST;

import static java.util.logging.Level.WARNING;
import javax.annotation.Nonnull;
import jenkins.model.lazy.BuildReference;
import jenkins.model.lazy.LazyBuildMixIn;

@@ -435,9 +436,19 @@ public abstract class AbstractBuildExecution extends Runner {

/**
* Returns the current {@link Node} on which we are building.
* @throws IllegalStateException if that cannot be determined
*/
protected final Node getCurrentNode() {
return Executor.currentExecutor().getOwner().getNode();
protected final @Nonnull Node getCurrentNode() throws IllegalStateException {
Executor exec = Executor.currentExecutor();
if (exec == null) {
throw new IllegalStateException("not being called from an executor thread");
}
Computer c = exec.getOwner();
Node node = c.getNode();
if (node == null) {
throw new IllegalStateException("no longer a configured node for " + c.getName());
}
return node;
}

public Launcher getLauncher() {
@@ -59,6 +59,7 @@
import static hudson.model.queue.Executables.*;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;


/**
@@ -68,7 +69,7 @@
*/
@ExportedBean
public class Executor extends Thread implements ModelObject {
protected final Computer owner;
protected final @Nonnull Computer owner;
private final Queue queue;

private long startTime;
@@ -109,7 +110,7 @@ public class Executor extends Thread implements ModelObject {
*/
private final List<CauseOfInterruption> causes = new Vector<CauseOfInterruption>();

public Executor(Computer owner, int n) {
public Executor(@Nonnull Computer owner, int n) {
super("Executor #"+n+" for "+owner.getDisplayName());
this.owner = owner;
this.queue = Jenkins.getInstance().getQueue();
@@ -523,7 +524,7 @@ public boolean hasStopPermission() {
return e!=null && Tasks.getOwnerTaskOf(getParentOf(e)).hasAbortPermission();
}

public Computer getOwner() {
public @Nonnull Computer getOwner() {
return owner;
}

0 comments on commit eedf51e

Please sign in to comment.