Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-23277] Better diagnosis for an NPE probably involving …
…cloud slaves.
  • Loading branch information
jglick committed Jun 2, 2014
1 parent 148251f commit 3f8fc4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 13 additions & 2 deletions core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -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;

Expand Down Expand Up @@ -435,9 +436,19 @@ deprecated class here.

/**
* 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() {
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/model/Executor.java
Expand Up @@ -59,6 +59,7 @@
import static hudson.model.queue.Executables.*;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;


/**
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -534,7 +535,7 @@ public boolean hasStopPermission() {
return e!=null && Tasks.getOwnerTaskOf(getParentOf(e)).hasAbortPermission();
}

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

Expand Down

0 comments on commit 3f8fc4e

Please sign in to comment.