Forums

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

Link Issue with groovy returning java.lang.NullPointerException

nkosi mbokazi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 6, 2018

HI,

im having issues with a script of Linking issues to another in a post function.

On some it returned a positive result and mostly it returns a null pointer exception. Below is my code: 

def fff = issue
def desc = issue.description
def reg = desc.find("(?i)WSM-[0-9][0-9][0-9][0-9]")

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueByKeyIgnoreCase(reg)

String ioio = issue

def issueObject = issueManager.getIssueObject(ioio)


def ComponentManager componentManager = ComponentManager.getInstance();
def issueLinkManager = ComponentAccessor.getIssueLinkManager();
def issueLinkTypeManager = componentManager.getComponentInstanceOfType(IssueLinkTypeManager.class);
def issueLT = issueLinkTypeManager.getIssueLinkType(11203);

def authContext = ComponentAccessor.getJiraAuthenticationContext()

def User = authContext.getLoggedInUser()

def linkID = issueLT.getId()

issueLinkManager.createIssueLink(issueObject.getId(), fff.getId(), (linkID), Long.valueOf(0), User)

 this is the result: 

There was an error during the execution of your script

Message:
java.lang.NullPointerException
Stack:
com.atlassian.jira.issue.link.DefaultIssueLinkManager.getIssueLink(DefaultIssueLinkManager.java:381)
com.atlassian.jira.issue.link.DefaultIssueLinkManager.createIssueLink(DefaultIssueLinkManager.java:89)
com.atlassian.jira.issue.link.IssueLinkManager$createIssueLink$0.call(Unknown Source)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
script15308646575551046973837.run(script15308646575551046973837.groovy:47)
com.innovalog.groovy.GroovyExpression.testScript(GroovyExpression.java:228)
com.innovalog.groovy.rest.GroovySupportRestApi.testScript(GroovySupportRestApi.java:212)
sun.reflect.GeneratedMethodAccessor6022.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)

thank you 

1 answer

0 votes
MoroSystems Support
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 8, 2018

Hello Nkosi,

in cases like this I would recommend you take a look into Jira source files. It is important to check the exact version of source files matching your running instance. I tried to check your problem on my 7.5.2 sources and it looks like there are some existing invalid links that don't have destination or linkType specified.

When I look at your script, I see that you are trying to create links from an issue to itself. Is it good? Couldn't this cause some inconsistencies in data that result in NullPointerException?

Regards,
Martin

Suggest an answer

Log in or Sign up to answer