Skip to content
Permalink
Browse files

[JENKINS-21511] - Prevent NPE in Graph visualization when thresholds …

…are not set
  • Loading branch information...
oleg-nenashev committed Jan 30, 2018
1 parent 8309ec9 commit f47bd2e6bed2befa4b01b0e810728d4f3e0628e9
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/main/java/hudson/plugins/helpers/GraphHelper.java
@@ -27,6 +27,8 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.annotation.CheckForNull;

/**
* TODO javadoc.
*
@@ -65,7 +67,7 @@ public static void redirectWhenGraphUnsupported(StaplerResponse rsp, StaplerRequ
rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
}

public static JFreeChart buildChart(final AbstractBuild<?, ?> build, final Integer functionCcnViolationThreshold, final Integer functionNcssViolationThreshold) {
public static JFreeChart buildChart(final AbstractBuild<?, ?> build, final @CheckForNull Integer functionCcnViolationThreshold, final @CheckForNull Integer functionNcssViolationThreshold) {

final JFreeChart chart = ChartFactory.createStackedAreaChart(
null, // chart title
@@ -176,9 +178,10 @@ public String getTitle() {
public long getCollectedNumber(AbstractBuildReport action) {
Collection<Statistic> functionResults = action.getResults().getFunctionResults();
int ccnViolatedFunctions = 0;


int threshold = functionCcnViolationThreshold != null ? functionCcnViolationThreshold.intValue() : 0;
for (Statistic statistic : functionResults) {
if(statistic.getCcn() > functionCcnViolationThreshold.intValue())
if(statistic.getCcn() > threshold)
ccnViolatedFunctions ++;
}
return ccnViolatedFunctions;
@@ -200,9 +203,10 @@ public String getTitle() {
public long getCollectedNumber(AbstractBuildReport action) {
Collection<Statistic> functionResults = action.getResults().getFunctionResults();
int ncssViolatedFunctions = 0;


int threshold = functionNcssViolationThreshold != null ? functionNcssViolationThreshold.intValue() : 0;
for (Statistic statistic : functionResults) {
if(statistic.getNcss() > functionNcssViolationThreshold.intValue())
if(statistic.getNcss() > threshold)
ncssViolatedFunctions ++;
}
return ncssViolatedFunctions;

0 comments on commit f47bd2e

Please sign in to comment.
You can’t perform that action at this time.