ScriptRunner Postfunction throws RuntimeException

Florian Zink March 9, 2014

Hi All,

I have a Scriptrunner postfunction in the "Create Issue" transition that sends out a custom email once it has been created. It all works very well and the email is always sent.

However, every time this postfunction is being executed and the mail is being sent, I receive the following exception in my logs:

2014-03-10 09:29:19,770 QuartzWorker-1 ERROR ServiceRunner    XXX! Email Support handler [atlassian.event.internal.EventPublisherImpl] There was an exception thrown trying to dispatch event 'com.atlassian.jira.event.issue.IssueEvent@7d553d9f[issue=TOOL-1239,comment=<null>,worklog=<null>,changelog=<null>,eventTypeId=1,sendMail=true,params={eventsource=workflow, baseurl=https://XXX.XXX.com},subtasksUpdated=false]' from the invoker 'com.atlassian.event.internal.SingleParameterMethodListenerInvoker@68ff9111'.
java.lang.RuntimeException: Cannot invoke method getName() on null object
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:60)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1.execute(AsynchronousAbleEventDispatcher.java:28)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:56)
	at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:151)
	at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:70)
	at com.atlassian.multitenant.event.DefaultPeeringEventPublisherManager.publish(DefaultPeeringEventPublisherManager.java:17)
	at com.atlassian.multitenant.event.PeeringEventPublisher.publish(PeeringEventPublisher.java:23)
	at com.atlassian.jira.event.issue.IssueEventDispatcher.dispatchEvent(IssueEventDispatcher.java:184)
	at com.atlassian.jira.event.issue.IssueEventDispatcher.dispatchEvent(IssueEventDispatcher.java:134)
	at com.atlassian.jira.workflow.function.event.FireIssueEventFunction.execute(FireIssueEventFunction.java:57)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:786)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:441)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:518)
	at com.atlassian.jira.service.util.handler.DefaultMessageHandlerContext.createIssue(DefaultMessageHandlerContext.java:73)
	at com.atlassian.jira.service.services.mail.DelegatingMessageHandlerContext.createIssue(DelegatingMessageHandlerContext.java:47)
	at com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler.handleMessage(CreateIssueHandler.java:242)
	at com.atlassian.jira.plugins.mail.handlers.CreateOrCommentHandler.handleMessage(CreateOrCommentHandler.java:133)
	at com.atlassian.jira.service.services.mail.MailFetcherService$1.process(MailFetcherService.java:361)
	at com.atlassian.jira.service.services.mail.MailFetcherService$MessageProviderImpl.getAndProcessMail(MailFetcherService.java:264)
	at com.atlassian.jira.service.services.mail.MailFetcherService.runImpl(MailFetcherService.java:349)
	at com.atlassian.jira.service.services.file.AbstractMessageHandlingService.run(AbstractMessageHandlingService.java:250)
	at com.atlassian.jira.service.JiraServiceContainerImpl.run(JiraServiceContainerImpl.java:61)
	at com.atlassian.jira.service.ServiceRunner.execute(ServiceRunner.java:47)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
	at com.atlassian.multitenant.quartz.MultiTenantThreadPool$MultiTenantRunnable.run(MultiTenantThreadPool.java:72)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.NullPointerException: Cannot invoke method getName() on null object

I put the postfunction at the end of the transition, so it is the last thing that's being executed.

The recipient of the custom email is the person who is the reporter of the ticket.

Thanks in advance.

Cheers

Florian




6 answers

1 accepted

2 votes
Answer accepted
Henning Tietgens
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.
March 9, 2014

There is a problem in your listener at DevActivityListener.workflowEvent(DevActivityListener.groovy:28)

So it seems it has nothing to do with the workflow postfunction.

Florian Zink March 9, 2014

Yay you were right!

I added a check in the listener, to see if the CurrentUser() is null or not. Now the listener functions are only executed when CurrentUser != null.

Thanks Henning!

0 votes
Florian Zink March 9, 2014

I tried it with your suggestion, but it didn't change anything. I'm still getting the same error in the logfiles.

I had once tried the same postfunction in a later workflow transition and it worked without any errors there. So my guess is, that the script has some problems with the timing, e.g. the script is running before the issue is being created entirely or something like that, b/c according to the exception it tries to get a name from some field and that field seems to be empty (null)

the complete stracktrace is as follows:

2014-03-10 12:54:44,603 QuartzWorker-0 ERROR ServiceRunner    XXX! Email Support handler [atlassian.event.internal.EventPublisherImpl] There was an exception thrown trying to dispatch event 'com.atlassian.jira.event.issue.IssueEvent@3bbd4b56[issue=TOOL-1222,comment=<null>,worklog=<null>,changelog=<null>,eventTypeId=1,sendMail=true,params={eventsource=workflow, baseurl=https://XXX.xxx.com},subtasksUpdated=false]' from the invoker 'com.atlassian.event.internal.SingleParameterMethodListenerInvoker@32632915'.
java.lang.RuntimeException: Cannot invoke method getName() on null object
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$2.run(AsynchronousAbleEventDispatcher.java:60)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1.execute(AsynchronousAbleEventDispatcher.java:28)
	at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:56)
	at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:151)
	at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:70)
	at com.atlassian.multitenant.event.DefaultPeeringEventPublisherManager.publish(DefaultPeeringEventPublisherManager.java:17)
	at com.atlassian.multitenant.event.PeeringEventPublisher.publish(PeeringEventPublisher.java:23)
	at com.atlassian.jira.event.issue.IssueEventDispatcher.dispatchEvent(IssueEventDispatcher.java:184)
	at com.atlassian.jira.event.issue.IssueEventDispatcher.dispatchEvent(IssueEventDispatcher.java:134)
	at com.atlassian.jira.workflow.function.event.FireIssueEventFunction.execute(FireIssueEventFunction.java:57)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:786)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:441)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:518)
	at com.atlassian.jira.service.util.handler.DefaultMessageHandlerContext.createIssue(DefaultMessageHandlerContext.java:73)
	at com.atlassian.jira.service.services.mail.DelegatingMessageHandlerContext.createIssue(DelegatingMessageHandlerContext.java:47)
	at com.atlassian.jira.plugins.mail.handlers.CreateIssueHandler.handleMessage(CreateIssueHandler.java:242)
	at com.atlassian.jira.plugins.mail.handlers.CreateOrCommentHandler.handleMessage(CreateOrCommentHandler.java:133)
	at com.atlassian.jira.service.services.mail.MailFetcherService$1.process(MailFetcherService.java:361)
	at com.atlassian.jira.service.services.mail.MailFetcherService$MessageProviderImpl.getAndProcessMail(MailFetcherService.java:264)
	at com.atlassian.jira.service.services.mail.MailFetcherService.runImpl(MailFetcherService.java:349)
	at com.atlassian.jira.service.services.file.AbstractMessageHandlingService.run(AbstractMessageHandlingService.java:250)
	at com.atlassian.jira.service.JiraServiceContainerImpl.run(JiraServiceContainerImpl.java:61)
	at com.atlassian.jira.service.ServiceRunner.execute(ServiceRunner.java:47)
	at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
	at com.atlassian.multitenant.quartz.MultiTenantThreadPool$MultiTenantRunnable.run(MultiTenantThreadPool.java:72)
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.NullPointerException: Cannot invoke method getName() on null object
	at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
	at DevActivityListener.workflowEvent(DevActivityListener.groovy:28)
	at com.atlassian.jira.event.issue.IssueEventListener$workflowEvent.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at com.onresolve.jira.groovy.canned.workflow.listeners.CustomListener.doScript(CustomListener.groovy:65)
	at com.onresolve.jira.groovy.canned.CannedScript$doScript.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at com.onresolve.jira.groovy.CannedScriptRunner.runCannedScript(CannedScriptRunner.groovy:63)
	at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:52)  <+3> (NativeMethodAccessorImpl.java:39) (DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
	at com.onresolve.jira.groovy.listener.ScriptRunnerUberListener$_workflowEvent_closure1.doCall(ScriptRunnerUberListener.groovy:48)  <+3> (NativeMethodAccessorImpl.java:39) (DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
	at groovy.lang.Closure.call(Closure.java:412)
	at groovy.lang.Closure.call(Closure.java:425)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1377)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1349)
	at org.codehaus.groovy.runtime.dgm$149.invoke(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at com.onresolve.jira.groovy.listener.ScriptRunnerUberListener.workflowEvent(ScriptRunnerUberListener.groovy:35)  <+3> (NativeMethodAccessorImpl.java:39) (DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36)
	... 29 more

0 votes
Henning Tietgens
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.
March 9, 2014

If this doesn't work please post the complete stack trace. It seems there is a part missing at the end.

0 votes
Henning Tietgens
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.
March 9, 2014

Did you get the error if you try

issue.issueTypeObject?.name == 'Support'

with the question mark in place?

0 votes
Florian Zink March 9, 2014

Hi Henning,

well, since it is a GUI where I input my parameters, I cannot give you a script.

But these are my parameters:

Condition: issue.issueTypeObject.name == 'Support'

Subject template: Ticket $issue created

Email type: HTML

To: reporter

include attachments: no

I think this problem can probably only be answered by Jamie, who wrote the ScriptRunner plugin.

0 votes
Henning Tietgens
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.
March 9, 2014

Could you post your postfunction script/config?

Suggest an answer

Log in or Sign up to answer