jenkinsci / mstest-plugin

Jenkins mstest plugin
https://plugins.jenkins.io/mstest/
MIT License
20 stars 29 forks source link

NullPointerException caused by MSTestPublisher.perform() #23

Closed Lukas0907 closed 1 year ago

Lukas0907 commented 1 year ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.414.2 OS: Linux - 6.1.0-12-amd64 Java: 17.0.8 - Debian (OpenJDK 64-Bit Server VM) --- active-directory:2.33 antisamy-markup-formatter:162.v0e6ec0fcfcf6 apache-httpcomponents-client-4-api:4.5.14-208.v438351942757 authentication-tokens:1.53.v1c90fd9191a_b_ blueocean:1.27.7 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.27.7 blueocean-commons:1.27.7 blueocean-config:1.27.7 blueocean-core-js:1.27.7 blueocean-dashboard:1.27.7 blueocean-display-url:2.4.2 blueocean-events:1.27.7 blueocean-git-pipeline:1.27.7 blueocean-github-pipeline:1.27.7 blueocean-i18n:1.27.7 blueocean-jwt:1.27.7 blueocean-personalization:1.27.7 blueocean-pipeline-api-impl:1.27.7 blueocean-pipeline-editor:1.27.7 blueocean-pipeline-scm-api:1.27.7 blueocean-rest:1.27.7 blueocean-rest-impl:1.27.7 blueocean-web:1.27.7 bootstrap5-api:5.3.2-1 bouncycastle-api:2.29 branch-api:2.1128.v717130d4f816 build-blocker-plugin:1.7.9 build-name-setter:2.3.0 build-timeout:1.31 build-user-vars-plugin:1.9 caffeine-api:3.1.8-133.v17b_1ff2e0599 change-assembly-version-plugin:1.10 checks-api:2.0.2 clone-workspace-scm:84.v147686859e1c cloudbees-bitbucket-branch-source:843.vd09104df7988 cloudbees-folder:6.848.ve3b_fd7839a_81 code-coverage-api:4.7.0 command-launcher:107.v773860566e2e commons-lang3-api:3.13.0-62.v7d18e55f51e2 commons-text-api:1.10.0-78.v3e7b_ea_d5a_fe1 conditional-buildstep:1.4.3 copyartifact:722.v0662a_9b_e22a_c credentials:1271.v54b_1c2c6388a_ credentials-binding:636.v55f1275c7b_27 dashboard-view:2.495.v07e81500c3f2 data-tables-api:1.13.6-4 display-url-api:2.3.9 durable-task:523.va_a_22cf15d5e0 echarts-api:5.4.0-6 email-ext:2.101 envinject:2.908.v66a_774b_31d93 envinject-api:1.199.v3ce31253ed13 external-monitor-job:215.v2e88e894db_f8 favorite:2.4.3 font-awesome-api:6.4.2-1 forensics-api:2.3.0 git:5.2.0 git-client:4.5.0 github:1.37.3 github-api:1.314-431.v78d72a_3fe4c3 github-branch-source:1741.va_3028eb_9fd21 gradle:2.8.2 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 htmlpublisher:1.32 instance-identity:173.va_37c494ec4e5 ionicons-api:56.v1b_1c8c49374e jackson2-api:2.15.2-350.v0c2f3f8fc595 jakarta-activation-api:2.0.1-3 jakarta-mail-api:2.0.1-3 javadoc:243.vb_b_503b_b_45537 javax-activation-api:1.2.0-6 javax-mail-api:1.6.2-9 jaxb:2.3.8-1 jdk-tool:73.vddf737284550 jenkins-design-language:1.27.7 jersey2-api:2.40-1 jira:3.11 jjwt-api:0.11.5-77.v646c772fddb_0 jobConfigHistory:1229.v3039470161a_d jobgenerator:1.22 jquery:1.12.4-1 jquery3-api:3.7.1-1 jsch:0.2.8-65.v052c39de79b_2 junit:1240.vf9529b_881428 mailer:463.vedf8358e006b_ mapdb-api:1.0.9-28.vf251ce40855d matrix-auth:3.2.1 matrix-project:808.v5a_b_5f56d6966 metrics:4.2.18-442.v02e107157925 mina-sshd-api-common:2.10.0-69.v28e3e36d18eb_ mina-sshd-api-core:2.10.0-69.v28e3e36d18eb_ msbuild:1.30 mstest:1.0.3 node-iterator-api:49.v58a_8b_35f8363 nuget:1.1 nunit:394.v65c09a_8408b_a_ okhttp-api:4.11.0-157.v6852a_a_fa_ec11 parameterized-trigger:2.46 pipeline-build-step:505.v5f0844d8d126 pipeline-graph-analysis:202.va_d268e64deb_3 pipeline-groovy-lib:689.veec561a_dee13 pipeline-input-step:477.v339683a_8d55e pipeline-milestone-step:111.v449306f708b_7 pipeline-model-api:2.2144.v077a_d1928a_40 pipeline-model-definition:2.2144.v077a_d1928a_40 pipeline-model-extensions:2.2144.v077a_d1928a_40 pipeline-rest-api:2.33 pipeline-stage-step:305.ve96d0205c1c6 pipeline-stage-tags-metadata:2.2144.v077a_d1928a_40 pipeline-stage-view:2.33 plain-credentials:143.v1b_df8b_d3b_e48 plugin-util-api:3.3.0 powershell:2.1 preSCMbuildstep:71.v1f2990a_37e27 prism-api:1.29.0-8 publish-over:0.22 publish-over-cifs:0.16 pubsub-light:1.17 redmine:0.21 resource-disposer:0.23 rich-text-publisher-plugin:1.5 run-condition:1.7 scm-api:676.v886669a_199a_a_ script-security:1275.v23895f409fb_d sidebar-link:2.2.4 snakeyaml-api:2.2-111.vc6598e30cc65 sonar:2.15 sse-gateway:1.26 ssh-credentials:308.ve4497b_ccd8f4 ssh-slaves:2.916.vd17b_43357ce4 sshd:3.312.v1c601b_c83b_0e structs:325.vcb_307d2a_2782 subversion:2.17.3 timestamper:1.26 token-macro:384.vf35b_f26814ec trilead-api:2.84.v72119de229b_7 variant:60.v7290fc0eb_b_cd vsphere-cloud:2.27 workflow-aggregator:596.v8c21c963d92d workflow-api:1281.vca_5fddb_3fceb_ workflow-basic-steps:1042.ve7b_140c4a_e0c workflow-cps:3791.va_c0338ea_b_59c workflow-durable-task-step:1289.v4d3e7b_01546b_ workflow-job:1346.v180a_63f40267 workflow-multibranch:756.v891d88f2cd46 workflow-scm-step:415.v434365564324 workflow-step-api:639.v6eca_cd8c04a_a_ workflow-support:865.v43e78cc44e0d ws-cleanup:0.45 ```

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

Reproduction steps

Since MSTest 1.0.3 publishing test results causes a NPE (see below). The offending line is https://github.com/jenkinsci/mstest-plugin/blob/master/src/main/java/hudson/plugins/mstest/MSTestPublisher.java#L140

System.setProperty() uses a ConcurrentHashMap which doesn't allow null values (neither as keys nor as values). Therefore either MsTestLogger.HUDSON_PLUGINS_MSTEST_LEVEL or this.logLevel must be null. Since the first is just a static field, I assume this.logLevel is somehow null. Maybe also caused by 0bc647db6f471a379ab6bcc47a896622eb81c901?

Expected Results

No exception.

Actual Results

ERROR: Build step failed with exception
java.lang.NullPointerException
    at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
    at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
    at java.base/java.util.Properties.put(Properties.java:1301)
    at java.base/java.util.Properties.setProperty(Properties.java:229)
    at java.base/java.lang.System.setProperty(System.java:999)
    at hudson.plugins.mstest.MSTestPublisher.perform(MSTestPublisher.java:140)
    at hudson.plugins.mstest.MSTestPublisher.perform(MSTestPublisher.java:131)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:767)
    at hudson.model.Build$BuildExecution.post2(Build.java:179)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711)
    at hudson.model.Run.execute(Run.java:1925)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
    at hudson.model.ResourceController.execute(ResourceController.java:101)
    at hudson.model.Executor.run(Executor.java:442)
Build step 'Publish MSTest test result report' marked build as failure

Anything else?

Downgrading to 1.0.1 fixed the problem. Maybe 1.0.3 is not compatible with the latest Jenkins LTS version (2.414.2)?

jonesbusy commented 1 year ago

This plugin some care and test on recent core version. I've open a PR here : https://github.com/jenkinsci/mstest-plugin/pull/24

Probably fallback on a default level is needed to avoid null levels

pavlovic-ivan commented 1 year ago

@jonesbusy @Lukas0907 Looks like this issue (or similar) was worked on some time ago in this PR: https://github.com/jenkinsci/mstest-plugin/pull/22. Issue still persists?

Lukas0907 commented 1 year ago

@jonesbusy @Lukas0907 Looks like this issue (or similar) was worked on some time ago in this PR: #22. Issue still persists?

I originally found this issue in v1.0.3 (which includes #22). Therefore I think this issue still persists.

pavlovic-ivan commented 1 year ago

Thanks @Lukas0907 . @manuel-rw can you please take a look at what Lukas mentioned above?

manuel-rw commented 1 year ago

Hi, I think that's mostly unrelated to my PR? Does the previous version 1.0.2 work? In our environment it is working fine, although we are never interested in the log outputs any only use the mentioned parts of the plugin.

jonesbusy commented 1 year ago

@Lukas0907 I have the feeling it happen when the plugin is upgraded from previous version to 1.0.3 without saving again the job configuration. When the descriptor is loaded from disk the log level is null. This is described here : https://www.jenkins.io/doc/developer/persistence/backward-compatibility/

Something like this

protected Object readResolve() {
  if (logLevel == null) {
    logLevel == 'DEBUG';
  }
  return this;
}
joe-kr commented 1 year ago

Got the same NPE as @Lukas0907 mentioned when publishing the test result from an existing freestyle job: This NPE occured after update to Jenkins LTS version (2.414.2) and mstest plugin from 1.0 to 1.0.3.

I tested also with a fresh docker installation of Jenkins LTS (2.414.3) and mstest plugin

Saving the job configuration will fix the NPE problem as @jonesbusy described in https://github.com/jenkinsci/mstest-plugin/issues/23#issuecomment-1780428228

jonesbusy commented 1 year ago

I can do the PR to add the missing readResolve() when the object is resurrected from persistence.

At least it will fix upgrade from 1.0.0 to 1.0.5 and up

jonesbusy commented 1 year ago

Should be fixed by https://github.com/jenkinsci/mstest-plugin/pull/26

jonesbusy commented 1 year ago

Can you check @pavlovic-ivan ? Would be nice to perform a release with also including #25 for at least validate pipeline support

pavlovic-ivan commented 1 year ago

On it @jonesbusy

pavlovic-ivan commented 1 year ago

Latest version is released. Thank everybody for raising the issue

Lukas0907 commented 1 year ago

Thank you for the fix! This resolved the issue for me.