提交 3f8fc4e2 编写于 作者: J Jesse Glick

[FIXED JENKINS-23277] Better diagnosis for an NPE probably involving cloud slaves.

上级 148251f9
......@@ -87,6 +87,7 @@ import javax.annotation.CheckForNull;
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 AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
/**
* 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 java.util.logging.Logger;
import static hudson.model.queue.Executables.*;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
......@@ -70,7 +71,7 @@ import javax.annotation.CheckForNull;
*/
@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 class Executor extends Thread implements ModelObject {
return e!=null && Tasks.getOwnerTaskOf(getParentOf(e)).hasAbortPermission();
}
public Computer getOwner() {
public @Nonnull Computer getOwner() {
return owner;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册