Skip to content

Commit

Permalink
[FIXED JENKINS-21999] If a slave node does not exist it will throw a
Browse files Browse the repository at this point in the history
null pointer exception. Instead we create a dummy launcher and return
that if it is unable to get the slave node.
  • Loading branch information
christ66 committed Feb 28, 2014
1 parent 2ae83f6 commit d2a2ec5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions core/src/main/java/hudson/Launcher.java
Expand Up @@ -841,6 +841,31 @@ public synchronized void close() throws IOException {
}
}

public static class DummyLauncher extends Launcher {

public DummyLauncher(TaskListener listener) {
super(listener, null);
}

@Override
public Proc launch(ProcStarter starter) throws IOException {
listener.error("Can not call launch on a dummy launcher.");
return null;
}

@Override
public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
listener.error("Can not call launchChannel on a dummy launcher.");
return null;
}

@Override
public void kill(Map<String, String> modelEnvVars) throws IOException, InterruptedException {
// Kill method should do nothing.
}
}


/**
* Launches processes remotely by using the given channel.
*/
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/hudson/model/Slave.java
Expand Up @@ -343,9 +343,21 @@ public byte[] readFully() throws IOException {

}

/**
* Creates a launcher for the slave.
*
* @return
* If there is no computer it will return a {@link hudson.Launcher.DummyLauncher}, otherwise it
* will return a {@link hudson.Launcher.RemoteLauncher} instead.
*/
public Launcher createLauncher(TaskListener listener) {
SlaveComputer c = getComputer();
return new RemoteLauncher(listener, c.getChannel(), c.isUnix()).decorateFor(this);
if (c == null) {
listener.error("Issue with creating launcher for slave " + name + ".");
return new Launcher.DummyLauncher(listener);
} else {
return new RemoteLauncher(listener, c.getChannel(), c.isUnix()).decorateFor(this);
}
}

/**
Expand Down

0 comments on commit d2a2ec5

Please sign in to comment.