Cannot get property 'name' on null object. Error line: Script427.groovy:14

Originally asked by Viacheslav on 19 September 2019 (original question)


We get an error at the second iteration of the sync process.
Incoming rules look as follows:

if(firstSync){
// If it’s the first sync for an issue (local issue does not exist yet)
// Set project key from source issue, if not found set a default
issue.projectKey = “LNOC”
// Set type name from source issue, if not found set a default
issue.typeName = “Incident”
}
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
issue.reporter = nodeHelper.getUser(replica.reporter?.key)
//issue.reporter = nodeHelper.getUserByEmail(replica.reporter?.email)
if (replica.status.name == “Escalated - Infra” && issue.status.name == “Waiting for customer” ) {
workflowHelper.transition(issue, “Respond to support”)
}

As I understand the error relates to the issue object and its status property, because when I remove it and keep only replica.status.name it starts working again.

Please, advise how to fix this issue.Source: Jira Cloud (old community)


Answer by André Leroy-Beaulieu Castro on 19 September 2019

Hi Viacheslav,

As you discovered, this error only occurs when the issue hasn’t been created, the workaround would be to use the following config in your script instead:

if (issue.status) {
* * 
    if (replica.status.name == "Escalated - Infra" && issue.status.name == "Waiting for customer") {    

     workflowHelper.transition(issue, "Respond to support")

    }
}

Thanks,

André


Answer by Niraj Kumar on 26 February 2024

To avoid the nullpointer, you can use the groovy safe navigation operator