Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73726

java.lang.NullPointerException: Cannot read field "group" because "this.this$0.thread" is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • workflow-cps-plugin

      After updating our "Pipleine: Groovy" plugin, we started to have a strange error. Whenever a pipeline fails, it raises NullPointerException and our post operations cannot run. All pipeline process gets interrupted. 

      It started with https://plugins.jenkins.io/workflow-cps/releases/#version_3946.v7935cb_edb_f82 and it is still happening with the latest release https://plugins.jenkins.io/workflow-cps/releases/#version_3953.v19f11da_8d2fa_ . We reverted our plugin to https://plugins.jenkins.io/workflow-cps/releases/#version_3943.v3519a_3260660 to prevent this issue. 

      It is happening on our Dev Jenkins which is working on a Linux machine with Java 21, but it is also happening on another Jenkins that has Windows and Java 11. On Windows one it just throws NullPointerException without any explanation but with the same callstack. I managed to write a simple pipeline that can reproduce the issue. If there are no parallel stages after throwing the error, exception is not raised.

      pipeline {
          options {
              parallelsAlwaysFailFast()
              buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '7', numToKeepStr: ''))
              timestamps()
          }
          agent none
          stages {
              stage ("Error Stage") {
                  when {
                      beforeAgent true
                      expression { true }
                  }
                  agent any
                  steps { 
                      echo "Echo"
                      error "Error"
                      echo "After Error"
                  }
                  
              }
              stage ("Parallel Stages") {
                  when {expression { true }}
                  parallel{
                      stage('Parallel 1') {
                      when {
                          beforeAgent true
                          expression { true }
                      }
                      agent any
                      steps {
                          echo "Echo Steps 1"
                      }
                      post {
                          cleanup {
                              echo "cleanup 1"
                          }
                          failure {
                              echo "failure 1"
                          }    
                          aborted {
                              echo "aborted 1"
                          }
                      }
                  }
                      stage('Parallel 2') {
                      when {
                          beforeAgent true
                          expression { true }
                      }
                      agent any
                      steps {
                          echo "Echo Steps 2"
                      }
                      post {
                          cleanup {
                              echo "cleanup 2"
                          }
                          failure {
                              echo "failure 2"
                          }    
                          aborted {
                              echo "aborted 2"
                          }
                      }
                  }
                  }
              }
          }
          post {
              failure {
                  echo "Failure"
              }
              always { 
                  echo "Always"
              }
          }
      } 

       

      16:02:03  Started by user Bilal Yaylak
      16:02:04  [Pipeline] Start of Pipeline
      16:02:05  [Pipeline] timestamps
      16:02:05  The timestamps step is unnecessary when timestamps are enabled for all Pipeline builds.
      16:02:05  [Pipeline] {
      16:02:05  [Pipeline] stage
      16:02:05  [Pipeline] { (Error Stage)
      16:02:05  [Pipeline] node
      16:02:05  Running on ******** in C:\JenkinsWorkspaces\1\workspace\groovy-plugin-test
      16:02:05  [Pipeline] {
      16:02:05  [Pipeline] echo
      16:02:05  Echo
      16:02:05  [Pipeline] error
      16:02:05  [Pipeline] }
      16:02:05  [Pipeline] // node
      16:02:05  [Pipeline] }
      16:02:05  [Pipeline] // stage
      16:02:05  [Pipeline] stage
      16:02:05  [Pipeline] { (Parallel Stages)
      16:02:05  Stage "Parallel Stages" skipped due to earlier failure(s)
      16:02:05  [Pipeline] getContext
      16:02:05  [Pipeline] parallel
      16:02:05  [Pipeline] { (Branch: Parallel 1)
      16:02:05  [Pipeline] { (Branch: Parallel 2)
      16:02:05  [Pipeline] stage
      16:02:05  [Pipeline] { (Parallel 1)
      16:02:05  [Pipeline] stage
      16:02:05  [Pipeline] { (Parallel 2)
      16:02:05  Stage "Parallel 1" skipped due to earlier failure(s)
      16:02:05  [Pipeline] getContext
      16:02:05  [Pipeline] }
      16:02:05  Stage "Parallel 2" skipped due to earlier failure(s)
      16:02:05  [Pipeline] getContext
      16:02:05  [Pipeline] }
      16:02:05  [Pipeline] // stage
      16:02:05  [Pipeline] // stage
      16:02:05  [Pipeline] }
      16:02:05  Failed in branch Parallel 1
      16:02:05  [Pipeline] }
      16:02:05  Failed in branch Parallel 2
      16:02:05  Terminating timestamps (id: 3)
      16:02:05  Terminating stage (id: 15)
      16:02:05  Terminating parallel (id: 18)
      16:02:05  [Pipeline] End of Pipeline
      16:02:05  Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: fcbd3f7d-7035-4377-9f95-5592f79ee7d6
      16:02:05  java.lang.NullPointerException: Cannot read field "group" because "this.this$0.thread" is null
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$2.onSuccess(CpsBodyExecution.java:254)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$2.onSuccess(CpsBodyExecution.java:249)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$4$1.run(CpsFlowExecution.java:995)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.lambda$wrap$2(CpsVmExecutorService.java:85)
      16:02:05  	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
      16:02:05  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
      16:02:05  	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      16:02:05  	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      16:02:05  	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      16:02:05  	at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
      16:02:05  	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
      16:02:05  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
      16:02:05  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
      16:02:05  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.call(CpsVmExecutorService.java:53)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.call(CpsVmExecutorService.java:50)
      16:02:05  	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
      16:02:05  	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
      16:02:05  	at PluginClassLoader for workflow-cps//org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.lambda$categoryThreadFactory$0(CpsVmExecutorService.java:50)
      16:02:05  	at java.base/java.lang.Thread.run(Thread.java:1583)
      16:02:05  Finished: FAILURE 

      I'd appreciate it if anyone could help, thank you in advance.

            jglick Jesse Glick
            bilalyaylak_sm Bilal
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: