Skip to content
Permalink
Browse files
[FIXED JENKINS-23277] Better diagnosis for an NPE probably involving …
…cloud slaves.
  • Loading branch information
jglick committed Jun 2, 2014
1 parent 148251f commit 3f8fc4e2ec5b1b421e1551a2a2fc2a284be330d1
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;


/**
@@ -70,7 +71,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;
@@ -111,7 +112,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();
@@ -534,7 +535,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 3f8fc4e

Please sign in to comment.