Skip to content

Commit

Permalink
Merge pull request #517 from jglick/JENKINS-14330
Browse files Browse the repository at this point in the history
JENKINS-14330: NPE from UnlabeldLoadStatistics.computeTotalExecutors
  • Loading branch information
jglick committed Jul 10, 2012
2 parents efd4aca + 5413470 commit a83782c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion changelog.html
Expand Up @@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
<code>NullPointerException</code> from <code>UnlabeldLoadStatistics</code> <i>[sic]</i>
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-14330">issue 14330</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/Computer.java
Expand Up @@ -88,6 +88,7 @@
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Inet4Address;
import javax.annotation.CheckForNull;

import static javax.servlet.http.HttpServletResponse.*;

Expand Down Expand Up @@ -425,7 +426,7 @@ public String getName() {
* null if the configuration has changed and the node is removed, yet the corresponding {@link Computer}
* is not yet gone.
*/
public Node getNode() {
public @CheckForNull Node getNode() {
if(nodeName==null)
return Jenkins.getInstance();
return Jenkins.getInstance().getNode(nodeName);
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/hudson/model/OverallLoadStatistics.java
Expand Up @@ -26,7 +26,6 @@
import hudson.model.MultiStageTimeSeries.TimeScale;
import hudson.model.MultiStageTimeSeries.TrendChart;
import jenkins.model.Jenkins;
import jenkins.model.UnlabeldLoadStatistics;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.export.Exported;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -590,7 +590,7 @@ protected void onModified() throws IOException {
* @since 1.467
*/
@Exported
public transient final LoadStatistics unlabeledLoad = new UnlabeldLoadStatistics();
public transient final LoadStatistics unlabeledLoad = new UnlabeledLoadStatistics();

/**
* {@link NodeProvisioner} that reacts to {@link #unlabeledLoad}.
Expand Down
Expand Up @@ -39,27 +39,32 @@
* @see OverallLoadStatistics
* @author Kohsuke Kawaguchi
*/
public class UnlabeldLoadStatistics extends LoadStatistics {
public class UnlabeledLoadStatistics extends LoadStatistics {

UnlabeldLoadStatistics() {
UnlabeledLoadStatistics() {
super(0, 0);
}

@Override
public int computeIdleExecutors() {
int r=0;
for (Computer c : Jenkins.getInstance().getComputers())
if(c.getNode().getMode()== Mode.NORMAL && (c.isOnline() || c.isConnecting()))
for (Computer c : Jenkins.getInstance().getComputers()) {
Node node = c.getNode();
if (node != null && node.getMode() == Mode.NORMAL && (c.isOnline() || c.isConnecting())) {
r += c.countIdle();
}
}
return r;
}

@Override
public int computeTotalExecutors() {
int r=0;
for (Computer c : Jenkins.getInstance().getComputers()) {
if(c.getNode().getMode()==Mode.NORMAL && c.isOnline())
Node node = c.getNode();
if (node != null && node.getMode() == Mode.NORMAL && c.isOnline()) {
r += c.countExecutors();
}
}
return r;
}
Expand Down

0 comments on commit a83782c

Please sign in to comment.