Skip to content

Commit

Permalink
[JENKINS-75091] Fix null pointer exception when title is missing (#169)
Browse files Browse the repository at this point in the history
https://issues.jenkins.io/browse/JENKINS-75091 provides a sample Pipeline
that throws a null pointer exception when viewing plots after a few
executions of the job.

pipeline {
    agent {
        label 'linux'
    }
    stages {
        stage('Hello') {
            steps {
                echo 'Hello World'
                sh '''#!/bin/bash
[ ! -f plot-a.csv ] && echo "Line-A,Line-B" > plot-a.csv
let "OTHER_VAR=2*BUILD_ID+1"
echo $BUILD_ID,$OTHER_VAR >> plot-a.csv
                '''
                plot csvFileName: 'plot-923ffed9-0b83-4a7d-93eb-55894c27e904.csv',
                     csvSeries: [[file: 'plot-a.csv']],
                     group: 'Z-group',
                     style: 'line'
                plot csvFileName: 'plot-923ffed9-0b83-4a7d-93eb-111111111111.csv',
                     csvSeries: [[file: 'plot-a.csv']],
		     group: 'Z-group',
		     style: 'line'
            }
        }
    }
}
  • Loading branch information
MarkEWaite authored Feb 17, 2025
1 parent 81a319a commit da41f6b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ public Double getDoubleFromString(String input) {
}

public int compareTo(Plot o) {
if (title == null) {

Check warning on line 428 in src/main/java/hudson/plugins/plot/Plot.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 428 is only partially covered, one branch is missing
return o == null || o.getTitle() == null ? 0 : -1;

Check warning on line 429 in src/main/java/hudson/plugins/plot/Plot.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 429 is not covered by tests
}
if (o == null || o.getTitle() == null) {

Check warning on line 431 in src/main/java/hudson/plugins/plot/Plot.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 431 is only partially covered, 2 branches are missing
return 1;

Check warning on line 432 in src/main/java/hudson/plugins/plot/Plot.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 432 is not covered by tests
}
return title.compareTo(o.getTitle());
}

Expand Down

0 comments on commit da41f6b

Please sign in to comment.