提交 554d9d55 编写于 作者: J Jesse Glick

Diagnosis of an NPE probably caused by a transient slave connection error.

java.lang.NullPointerException
	at hudson.tasks.CommandInterpreter.createScriptFile(CommandInterpreter.java:104)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
	at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
	at com.cloudbees.hudson.plugins.modeling.impl.builder.BuilderImpl.perform(BuilderImpl.java:58)
	at hudson.plugins.m2extrasteps.M2ExtraStepsWrapper.executeBuildSteps(M2ExtraStepsWrapper.java:166)
	at hudson.plugins.m2extrasteps.M2ExtraStepsWrapper.access$200(M2ExtraStepsWrapper.java:43)
	at hudson.plugins.m2extrasteps.M2ExtraStepsWrapper$1.tearDown(M2ExtraStepsWrapper.java:137)
	at hudson.maven.MavenModuleSetBuild$RunnerImpl.doRun(MavenModuleSetBuild.java:817)
	at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:490)
	at hudson.model.Run.run(Run.java:1442)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:239)
上级 90b0f29e
......@@ -263,7 +263,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
* @return
* null, for example if the slave that this build run no longer exists.
*/
public Node getBuiltOn() {
public @CheckForNull Node getBuiltOn() {
if (builtOn==null || builtOn.equals(""))
return Jenkins.getInstance();
else
......
......@@ -37,6 +37,7 @@ import java.io.IOException;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import jenkins.model.Configuration;
......@@ -143,7 +144,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup<TopLevelI
throw new IllegalStateException("Trying to remove unknown computer");
}
/*package*/ Computer getComputer(Node n) {
/*package*/ @CheckForNull Computer getComputer(Node n) {
Map<Node,Computer> computers = getComputerMap();
return computers.get(n);
}
......
......@@ -25,14 +25,11 @@
package hudson.model;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Util;
import hudson.cli.declarative.CLIMethod;
import hudson.cli.declarative.CLIResolver;
import hudson.console.AnnotatedLargeText;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.Descriptor.FormException;
import hudson.model.labels.LabelAtom;
......@@ -81,7 +78,6 @@ import javax.servlet.ServletException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
......@@ -100,6 +96,7 @@ import java.net.Inet4Address;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import static javax.servlet.http.HttpServletResponse.*;
......@@ -281,7 +278,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* @return
* never null when {@link #isOffline()}==false.
*/
public abstract VirtualChannel getChannel();
public abstract @Nullable VirtualChannel getChannel();
/**
* Gets the default charset of this computer.
......
......@@ -57,6 +57,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import jenkins.model.Jenkins;
import jenkins.util.io.OnMaster;
......@@ -159,7 +160,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
* this method can return null if there's no {@link Computer} object for this node,
* such as when this node has no executors at all.
*/
public final Computer toComputer() {
public final @CheckForNull Computer toComputer() {
AbstractCIBase ciBase = Jenkins.getInstance();
return ciBase.getComputer(this);
}
......@@ -169,7 +170,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
*
* This is just a convenience method for {@link Computer#getChannel()} with null check.
*/
public final VirtualChannel getChannel() {
public final @CheckForNull VirtualChannel getChannel() {
Computer c = toComputer();
return c==null ? null : c.getChannel();
}
......@@ -364,7 +365,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
/**
* Gets the {@link FilePath} on this node.
*/
public FilePath createPath(String absolutePath) {
public @CheckForNull FilePath createPath(String absolutePath) {
VirtualChannel ch = getChannel();
if(ch==null) return null; // offline
return new FilePath(ch,absolutePath);
......
......@@ -39,6 +39,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.CheckForNull;
/**
* {@link CopyOnWriteArrayList} for {@link Node} that has special serialization semantics
......@@ -67,7 +68,7 @@ public final class NodeList extends ArrayList<Node> {
this(Arrays.asList(toCopyIn));
}
public Node getNode(String nodeName) {
public @CheckForNull Node getNode(String nodeName) {
return map.get(nodeName);
}
......
......@@ -29,10 +29,12 @@ import hudson.Util;
import hudson.EnvVars;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Node;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Nonnull;
/**
* Common part between {@link Shell} and {@link BatchFile}.
......@@ -60,6 +62,13 @@ public abstract class CommandInterpreter extends Builder {
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
FilePath ws = build.getWorkspace();
if (ws == null) {
Node node = build.getBuiltOn();
if (node == null) {
throw new NullPointerException("no such build node: " + build.getBuiltOnStr());
}
throw new NullPointerException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel());
}
FilePath script=null;
try {
try {
......@@ -100,7 +109,7 @@ public abstract class CommandInterpreter extends Builder {
/**
* Creates a script file in a temporary name in the specified directory.
*/
public FilePath createScriptFile(FilePath dir) throws IOException, InterruptedException {
public FilePath createScriptFile(@Nonnull FilePath dir) throws IOException, InterruptedException {
return dir.createTextTempFile("hudson", getFileExtension(), getContents(), false);
}
......
......@@ -1635,7 +1635,7 @@ public class Jenkins extends AbstractCIBase implements ModifiableTopLevelItemGro
/**
* Gets the slave node of the give name, hooked under this Hudson.
*/
public Node getNode(String name) {
public @CheckForNull Node getNode(String name) {
return slaves.getNode(name);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册