Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

getting null pointer exception in logs.

Jyotsna Chimakurthi November 1, 2022

I am getting "java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object " error for the below script.

Please help to how to resolve the issue.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.label.LabelManager
import static com.atlassian.jira.issue.IssueFieldConstants.*

def issueManager = ComponentAccessor.getIssueManager()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectsByName("Epic Link").first()
def linkedEpic = contextIssue.getCustomFieldValue(epicLinkCf) as Issue
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(contextIssue.id)

if (getBehaviourContextId() == "FEA") {

getFieldById("summary").setFormValue("${contextIssue.summary}")
getFieldById("issuelinks-linktype").setFormValue("delivers")
getFieldById("issuelinks-issues").setFormValue(contextIssue.key)

if ((linkedEpic) != null)
{
getFieldByName("Epic Link").setFormValue(linkedEpic.key)
}
def values = []

labels.each { values.add(it.getLabel()) }

def labelField = getFieldById(LABELS)

labelField.setFormValue(values)
}

1 answer

0 votes
Nir Haimov
Community Champion
November 2, 2022

Hi @Jyotsna Chimakurthi 

Try to change:

def epicLinkCf = customFieldManager.getCustomFieldObjectsByName("Epic Link").first()

To:

def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

also, make sure you have the "Epic Link" field in the issue it fails on... 

Suggest an answer

Log in or Sign up to answer