java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Aleksey Didik,
  • 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.
    via by Aleksey Didik,
    • java.lang.NullPointerException at org.jenkinsci.plugins.sonargerrit.SonarToGerritBuilder.perform(SonarToGerritBuilder.java:149)
    No Bugmate found.