jenkinsci / code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
https://plugins.jenkins.io/code-coverage-api/
MIT License
112 stars 75 forks source link

NullPointerException in publishCoverage step after upgrading from 2.0.4 to 3.0.2 #426

Closed ryanfitzsimon closed 2 years ago

ryanfitzsimon commented 2 years ago

Jenkins and plugins versions report

Environment ``` Jenkins: 2.346.1 OS: Windows Server 2016 - 10.0 --- Office-365-Connector:4.17.0 ace-editor:1.1 active-directory:2.25.1 ant:475.vf34069fef73c antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 authentication-tokens:1.4 authorize-project:1.4.0 basic-branch-build-strategies:1.3.2 blueocean:1.25.5 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.25.5 blueocean-commons:1.25.5 blueocean-config:1.25.5 blueocean-core-js:1.25.5 blueocean-dashboard:1.25.5 blueocean-display-url:2.4.1 blueocean-events:1.25.5 blueocean-git-pipeline:1.25.5 blueocean-github-pipeline:1.25.5 blueocean-i18n:1.25.5 blueocean-jira:1.25.5 blueocean-jwt:1.25.5 blueocean-personalization:1.25.5 blueocean-pipeline-api-impl:1.25.5 blueocean-pipeline-editor:1.25.5 blueocean-pipeline-scm-api:1.25.5 blueocean-rest:1.25.5 blueocean-rest-impl:1.25.5 blueocean-web:1.25.5 bootstrap4-api:4.6.0-5 bootstrap5-api:5.1.3-7 bouncycastle-api:2.26 branch-api:2.1046.v0ca_37783ecc5 build-timeout:1.21 caffeine-api:2.9.3-65.v6a_47d0f4d1fe checks-api:1.7.4 cloud-stats:0.27 cloudbees-bitbucket-branch-source:773.v4b_9b_005b_562b_ cloudbees-folder:6.729.v2b_9d1a_74d673 code-coverage-api:3.0.3 codecover:1.1 command-launcher:84.v4a_97f2027398 config-file-provider:3.10.0 copyartifact:1.46.4 credentials:1139.veb_9579fca_33b_ credentials-binding:523.vd859a_4b_122e6 data-tables-api:1.12.1-2 display-url-api:2.3.6 docker-commons:1.19 docker-java-api:3.2.13-37.vf3411c9828b9 docker-plugin:1.2.9 docker-workflow:1.29 durable-task:496.va67c6f9eefa7 echarts-api:5.3.3-1 embeddable-build-status:2.0.4 extended-read-permission:3.2 external-monitor-job:191.v363d0d1efdf8 favorite:2.4.1 font-awesome-api:6.1.1-1 forensics-api:1.15.1 git:4.11.3 git-client:3.11.0 git-server:1.11 gitea:1.4.3 github:1.34.4 github-api:1.303-400.v35c2d8258028 github-branch-source:1656.v77eddb_b_e95df handlebars:3.0.8 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 htmlpublisher:1.30 jackson2-api:2.13.3-285.vc03c0256d517 javadoc:217.v905b_86277a_2a_ javax-activation-api:1.2.0-3 javax-mail-api:1.6.2-6 jaxb:2.3.6-1 jclouds-jenkins:2.29 jdk-tool:1.5 jenkins-design-language:1.25.5 jira:3.7.1 jjwt-api:0.11.5-77.v646c772fddb_0 job-dsl:1.80 jquery-detached:1.2.1 jquery3-api:3.6.0-4 jsch:0.1.55.2 junit:1119.1121.vc43d0fc45561 ldap:2.10 lockable-resources:2.15 mailer:414.vcc4c33714601 mapdb-api:1.0.9.0 matrix-auth:3.1.5 matrix-project:772.v494f19991984 maven-plugin:3.19 mercurial:2.16.2 mina-sshd-api-common:2.8.0-21.v493b_6b_db_22c6 mina-sshd-api-core:2.8.0-21.v493b_6b_db_22c6 momentjs:1.1.1 monitoring:1.91.0 nunit:0.27 okhttp-api:4.9.3-105.vb96869f8ac3a opencover:1.0.3 pam-auth:1.8 pipeline-build-step:2.18 pipeline-github-lib:38.v445716ea_edda_ pipeline-graph-analysis:195.v5812d95a_a_2f9 pipeline-groovy-lib:593.va_a_fc25d520e9 pipeline-input-step:449.v77f0e8b_845c4 pipeline-milestone-step:101.vd572fef9d926 pipeline-model-api:2.2097.v33db_b_de764b_e pipeline-model-definition:2.2097.v33db_b_de764b_e pipeline-model-extensions:2.2097.v33db_b_de764b_e pipeline-rest-api:2.24 pipeline-stage-step:293.v200037eefcd5 pipeline-stage-tags-metadata:2.2097.v33db_b_de764b_e pipeline-stage-view:2.24 pipeline-utility-steps:2.13.0 plain-credentials:1.8 plugin-util-api:2.17.0 popper-api:1.16.1-3 popper2-api:2.11.5-2 prism-api:1.28.0-2 pubsub-light:1.16 resource-disposer:0.19 scm-api:608.vfa_f971c5a_a_e9 script-security:1175.v4b_d517d6db_f0 snakeyaml-api:1.30.2-76.vc104f7ce9870 sse-gateway:1.25 ssh-credentials:291.v8211e4f8efb_c ssh-slaves:1.821.vd834f8a_c390e sshd:3.242.va_db_9da_b_26a_c3 structs:318.va_f3ccb_729b_71 subversion:2.15.5 swarm:3.33 thinBackup:1.10 timestamper:1.18 token-macro:293.v283932a_0a_b_49 trilead-api:1.57.v6e90e07157e1 variant:1.4 windows-slaves:1.8.1 workflow-aggregator:590.v6a_d052e5a_a_b_5 workflow-api:1188.v0016b_4f29881 workflow-basic-steps:969.vc4ec3e4854b_f workflow-cps:2746.v0da_83a_332669 workflow-durable-task-step:1174.v73a_9a_17edce0 workflow-job:1203.v7b_7023424efe workflow-multibranch:716.vc692a_e52371b_ workflow-scm-step:400.v6b_89a_1317c9a_ workflow-step-api:625.vd896b_f445a_f8 workflow-support:827.v7ef666c4d65c ws-cleanup:0.42 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Controller OS: Windows Server 2016 Agent OS: Windows Server 2019

Reproduction steps

After upgrading Code Coverage API 2.0.4 to 3.0.2 I started seeing failures in the publishCoverage step shown in the snippet below for all branches in a multibranch pipeline job.

post {
  always {
    storeArtifacts(["logs/*.binlog"])
    nunit testResultsPattern: "working/test/cs/nunit/*.xml"
    zipToArtifact("working/C# Unit Test Results.zip", "working/test/cs")
    publishCoverage adapters: [opencoverAdapter(mergeToOneReport: true, path: "working/test/cs/coverlet/**/*.xml")], sourceFileResolver: sourceFiles('NEVER_STORE')
  }
  cleanup {
    deleteDir()
  }
}

I tried updating to 3.0.3 when it was released, but the failures continued.

Downgrading to Code Coverage API 2.0.4 resolved the issue.

Expected Results

For reference, the "Node Publish Coverage Report" pipeline step console output from a successful build (with 2.0.4) looks like this:

17:30:03 Publishing Coverage report....
17:30:07 A total of 1 reports were found
17:30:08 Report coverage diff: 0.0%. Add to CoverageResult.
17:30:08 Module coverage diff: 0.0%. Add to CoverageResult.
17:30:08 Class coverage diff: 0.0%. Add to CoverageResult.
17:30:08 Method coverage diff: 0.0%. Add to CoverageResult.
17:30:08 Line coverage diff: 0.0%. Add to CoverageResult.
17:30:08 Conditional coverage diff: 0.0%. Add to CoverageResult.
17:30:08 [Coverage] Computing coverage delta report
17:30:08 [Coverage] Reference build recorder is not configured
17:30:08 [Coverage] -> No reference build defined, falling back to previous build
17:30:08 [Coverage] -> Found reference result 'io.jenkins.plugins.coverage.CoverageAction@3c96fdaa'
17:30:12 [Checks API] No suitable checks publisher found.

Actual Results

For a failed build using 3.0.3, the console output was:

16:37:56 Publishing Coverage report....
16:37:58 A total of 1 reports were found
16:37:59 Report coverage diff: 0.0%. Add to CoverageResult.
16:37:59 Module coverage diff: 0.0%. Add to CoverageResult.
16:37:59 Class coverage diff: 0.0%. Add to CoverageResult.
16:37:59 Method coverage diff: 0.008125305%. Add to CoverageResult.
16:37:59 Line coverage diff: 0.0036010742%. Add to CoverageResult.
16:37:59 Conditional coverage diff: -0.008071899%. Add to CoverageResult.
16:37:59 [Coverage] Computing coverage delta report
16:37:59 [Coverage] Reference build recorder is not configured
16:37:59 [Coverage] -> No reference build defined, falling back to previous build
16:37:59 [Coverage] -> Found reference result 'io.jenkins.plugins.coverage.CoverageAction@227dacf6'

The following error is shown in the "Node Publish Coverage Report" pipeline step status page:

java.lang.NullPointerException
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.createNode(CoverageNodeConverter.java:64)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.createNode(CoverageNodeConverter.java:41)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.convert(CoverageNodeConverter.java:34)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.createNode(CoverageNodeConverter.java:56)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.convert(CoverageNodeConverter.java:34)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.createNode(CoverageNodeConverter.java:56)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.convert(CoverageNodeConverter.java:34)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.createNode(CoverageNodeConverter.java:56)
    at io.jenkins.plugins.coverage.model.CoverageNodeConverter.convert(CoverageNodeConverter.java:34)
    at io.jenkins.plugins.coverage.model.CoverageReporter.run(CoverageReporter.java:71)
    at io.jenkins.plugins.coverage.CoverageProcessor.performCoverageReport(CoverageProcessor.java:133)
    at io.jenkins.plugins.coverage.CoveragePublisher.perform(CoveragePublisher.java:114)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Anything else?

Based on the stack trace, it seems like result.getAdditionalProperty("lineNumber") might be returning null here.

Is it possible that the CoverageResult passed in by CoverageProcessor.performCoverageReport() (created by CoverageProcessor.aggregateReports() here might not have the "lineNumber" property?

uhafner commented 2 years ago

Thanks for reporting! You are right the "old" model has no such property and returns null rather than an empty set. A really poor API, I should get rid of the old model.

ryanfitzsimon commented 2 years ago

I can confirm that the issue we were seeing is resolved after updating to 3.0.4.

Thanks for all the great work @uhafner!