It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script runner - java.lang.NullPointerException: Cannot invoke method getAt() on null object Edited


I am keep getting this error "java.lang.NullPointerException: Cannot invoke method getAt() on null object" on the lest line on the below code "def DefectLinkedIssue = ....."

the relevant part of the code:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def DocumentationlinkName = 'Documentation Task'

def DefectLinkedIssue = ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)[0]


3 answers

1 accepted

the [0] is what gives you the message when there are no issues in 

ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)

 this could work 

def DefectLinkedIssueCollection = ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)

if (DefectLinkedIssueCollection?.size() >0) {
def DefectLinkedIssue = DefectLinkedIssueCollection[0]
// there are no links


@fran garcia gomera  Thank you so much for helping me. it worked!!! 

hello, because this part

ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)

returns you empty list, hence it can't get element at 0's key

are you sure you are looking for outward issues, or that link name is correct?

I'd recommend experimenting in script console by replasing line 

def issue = event.issue as Issue


def issue = ComponentAccessor.issueManager.getIssueObject("JIRA-123")

(replace JIRA-123 with your issue key)


Looks like getName() and getOutward() return different values.

For e.g. I have link name "clones"

getOutward() returns "clones" ,but getName() returns "Cloners"

See this code it could be helpful


import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser

IssueManager im = ComponentAccessor.getComponent(IssueManager);
IssueLinkManager ism = ComponentAccessor.getComponent(IssueLinkManager);
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Issue createdIssue = im.getIssueByKeyIgnoreCase('<IssueKey>');

LinkCollection issueLinksCol = ism.getLinkCollection(createdIssue, currentUser);
Collection<Issue> linkedIssuesCol = issueLinksCol.getAllIssues()

def result="start...<br>";

for (Issue linkedIssue : linkedIssuesCol) {


Set<IssueLinkType> linkTypesSet = issueLinksCol.getLinkTypes()
String linkName ='clones';
for (IssueLinkType ilt: linkTypesSet){




List<Issue> myList = issueLinksCol.getOutwardIssues(linkName);

for (Issue iss : myList) {
result+=iss.getKey()+" a <br>";



Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

273 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you