diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 651130517674364065f41172cb8a9d05ce4b6b4f..d47ec824474d3ce8a12aef35fbf893a0f99682c7 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -457,7 +457,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces * Returns {@link Node#getNodeName() the name of the node}. */ public @Nonnull String getName() { - return nodeName; + return nodeName != null ? nodeName : ""; } /** diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index d5974aa1896a9b055fb70c2d2ce7e3f617da93e0..fe9fbe08419e73769ea3af64e85b3c703a5224fd 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -117,7 +117,7 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable * "" if this is master */ @Exported(visibility=999) - public abstract String getNodeName(); + public abstract @Nonnull String getNodeName(); /** * When the user clones a {@link Node}, Hudson uses this method to change the node name right after diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index e52a6f8af5261614a52a67d36170012d293811e9..d29ed99a13f2f24fb7b67af3df3924c8ecacc370 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -56,8 +56,8 @@ import java.util.Set; import javax.servlet.ServletException; -import hudson.util.TimeUnit2; import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import jenkins.model.Jenkins; import jenkins.slaves.WorkspaceLocator; @@ -149,7 +149,7 @@ public abstract class Slave extends Node implements Serializable { this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList()); } - public Slave(String name, String nodeDescription, String remoteFS, int numExecutors, + public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List> nodeProperties) throws FormException, IOException { this.name = name; this.description = nodeDescription; diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java index ea78e80331c7e6a44fe23e56390e1fcd1c9f59d8..3a73b99829f9569df3bed17d48c4bd12cd5bd36e 100644 --- a/core/src/main/java/hudson/slaves/SlaveComputer.java +++ b/core/src/main/java/hudson/slaves/SlaveComputer.java @@ -170,7 +170,13 @@ public class SlaveComputer extends Computer { @Override public Slave getNode() { - return (Slave)super.getNode(); + Node node = super.getNode(); + if (node == null || node instanceof Slave) { + return (Slave)node; + } else { + logger.log(Level.WARNING, "found an unexpected kind of node {0} from {1} with nodeName={2}", new Object[] {node, this, nodeName}); + return null; + } } @Override