java.lang.NullPointerException

Jenkins JIRA | Aleksey Didik | 1 year ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    In case if the plugin is run out of a job with Gerrit Trigger, plugin fails with NPE: {noformat} java.lang.NullPointerException at org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform(SonarToGerritBuilder.java:149) {noformat} It happens because the plugin tries to get current Gerrit server name from GerritTrigger instance in current job and can't find it. Overall, the plugin must support run in jobs which have no GerritTrigger instance, for example in subjobs of multijob, or workflow jobs. There's a three parameters plugin needs to post changes to Gerrt: * Server name - used to get REST API information from GerritManagement. * Change number - Used to retrieve necessary change from Gerrit server. * Patchset number - Used to retrieve necessary patchset from Gerrit server. In current GerritTrigger implementation all parameters are put in environment parameters by Gerrit triiger on tirggering: * Server name - GERRIT_NAME * Change number - GERRIT_CHANGE_NUMBER * Patchset number - GERRIT_PATCHSET_NUMBER So to support the plugin work in any job those parameters must be available as enviroment variables, what is pretty easy to do and pass from main job with GerritTrigger. To support such run plugin must follow the next logic: *When* GERRIT_NAME is available in current build EnvVars, *Then* use is as server name. *When* GERRIT_NAME is not available in current build EnvVars, *Then* use GerritTrigger.getTrigger(build.getProject()) to get trigger instance for current job and get server name from the instance. *When* GERRIT_NAME is not available in current build EnvVars and there's no gerrit trigger instance for this job, *Then* log error and fail build step. Additional section of wiki is required to describe steps to run plugin in job without GerritTrigger plugin inside.

    Jenkins JIRA | 1 year ago | Aleksey Didik
    java.lang.NullPointerException
  2. 0

    In case if the plugin is run out of a job with Gerrit Trigger, plugin fails with NPE: {noformat} java.lang.NullPointerException at org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform(SonarToGerritBuilder.java:149) {noformat} It happens because the plugin tries to get current Gerrit server name from GerritTrigger instance in current job and can't find it. Overall, the plugin must support run in jobs which have no GerritTrigger instance, for example in subjobs of multijob, or workflow jobs. There's a three parameters plugin needs to post changes to Gerrt: * Server name - used to get REST API information from GerritManagement. * Change number - Used to retrieve necessary change from Gerrit server. * Patchset number - Used to retrieve necessary patchset from Gerrit server. In current GerritTrigger implementation all parameters are put in environment parameters by Gerrit triiger on tirggering: * Server name - GERRIT_NAME * Change number - GERRIT_CHANGE_NUMBER * Patchset number - GERRIT_PATCHSET_NUMBER So to support the plugin work in any job those parameters must be available as enviroment variables, what is pretty easy to do and pass from main job with GerritTrigger. To support such run plugin must follow the next logic: *When* GERRIT_NAME is available in current build EnvVars, *Then* use is as server name. *When* GERRIT_NAME is not available in current build EnvVars, *Then* use GerritTrigger.getTrigger(build.getProject()) to get trigger instance for current job and get server name from the instance. *When* GERRIT_NAME is not available in current build EnvVars and there's no gerrit trigger instance for this job, *Then* log error and fail build step. Additional section of wiki is required to describe steps to run plugin in job without GerritTrigger plugin inside.

    Jenkins JIRA | 1 year ago | Aleksey Didik
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform()
    2. org.jenkinsci.plugins
      SonarToGerritBuilder.perform
      1. org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform(SonarToGerritBuilder.java:149)
      1 frame