Navigation Menu

Skip to content

Commit

Permalink
[FIXED JENKINS-15369] NPE deleting a slave.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 1, 2012
1 parent 33ad9e0 commit 300bfc4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
NPE deleting a slave.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15369">issue 15369</a>)
<li class=bug>
Deadlock involving views.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15368">issue 15368</a>)
Expand Down
20 changes: 16 additions & 4 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -30,6 +30,7 @@
import hudson.cli.declarative.CLIResolver;
import hudson.console.AnnotatedLargeText;
import hudson.model.Descriptor.FormException;
import hudson.model.labels.LabelAtom;
import hudson.model.queue.WorkUnit;
import hudson.node_monitors.NodeMonitor;
import hudson.remoting.Channel;
Expand Down Expand Up @@ -454,7 +455,7 @@ public String getName() {

@Exported
public LoadStatistics getLoadStatistics() {
return getNode().getSelfLabel().loadStatistics;
return LabelAtom.get(nodeName != null ? nodeName : "").loadStatistics;
}

public BuildTimelineWidget getTimeline() {
Expand Down Expand Up @@ -566,7 +567,10 @@ public void setTemporarilyOffline(boolean temporarilyOffline) {
public void setTemporarilyOffline(boolean temporarilyOffline, OfflineCause cause) {
offlineCause = temporarilyOffline ? cause : null;
this.temporarilyOffline = temporarilyOffline;
getNode().setTemporaryOfflineCause(offlineCause);
Node node = getNode();
if (node != null) {
node.setTemporaryOfflineCause(offlineCause);
}
Jenkins.getInstance().getQueue().scheduleMaintenance();
synchronized (statusChangeLock) {
statusChangeLock.notifyAll();
Expand Down Expand Up @@ -1108,7 +1112,11 @@ public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOE
String name = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
Jenkins.checkGoodName(name);

Node result = getNode().reconfigure(req, req.getSubmittedForm());
Node node = getNode();
if (node == null) {
throw new ServletException("No such node " + nodeName);
}
Node result = node.reconfigure(req, req.getSubmittedForm());
replaceBy(result);

// take the user back to the slave top page.
Expand Down Expand Up @@ -1165,7 +1173,11 @@ private void replaceBy(Node newNode) throws ServletException, IOException {
@CLIMethod(name="delete-node")
public HttpResponse doDoDelete() throws IOException {
checkPermission(DELETE);
Jenkins.getInstance().removeNode(getNode());
Node node = getNode();
if (node == null) {
throw new IOException("Cannot delete " + nodeName + " since it does not still exist");
}
Jenkins.getInstance().removeNode(node);
return new HttpRedirect("..");
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/model/labels/LabelAtom.java
Expand Up @@ -57,6 +57,8 @@
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

/**
* Atomic single token label, like "foo" or "bar".
Expand Down Expand Up @@ -216,8 +218,9 @@ public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOE

/**
* Obtains an atom by its {@linkplain #getName() name}.
* @see Jenkins#getLabelAtom
*/
public static LabelAtom get(String l) {
public static @Nullable LabelAtom get(@CheckForNull String l) {
return Jenkins.getInstance().getLabelAtom(l);
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -295,6 +295,8 @@
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Root object of the system.
Expand Down Expand Up @@ -1558,8 +1560,9 @@ public Label getLabel(String expr) {

/**
* Returns the label atom of the given name.
* @return non-null iff name is non-null
*/
public LabelAtom getLabelAtom(String name) {
public @Nullable LabelAtom getLabelAtom(@CheckForNull String name) {
if (name==null) return null;

while(true) {
Expand Down Expand Up @@ -1669,7 +1672,7 @@ public synchronized void addNode(Node n) throws IOException {
/**
* Removes a {@link Node} from Hudson.
*/
public synchronized void removeNode(Node n) throws IOException {
public synchronized void removeNode(@Nonnull Node n) throws IOException {
Computer c = n.toComputer();
if (c!=null)
c.disconnect(OfflineCause.create(Messages._Hudson_NodeBeingRemoved()));
Expand Down

0 comments on commit 300bfc4

Please sign in to comment.