Groovy Scripted Fields: javax.script.ScriptException: java.lang.NullPointerException

Hi,

I've configured a scripted 'Number' field in Jira which holds the resultset value from groovy script by querying the Table Grid Editor plugin's customfield via database tables. Below is the line in groovy which returns value from the table -

Sql sql = new Sql(connection);
GroovyRowResult rowResult = sql.firstRow("SELECT SUM(col) AS total FROM TABLEGRID_C10XXX WHERE issueid = ${issue.getId()}");

Double total = null;
total = rowResult.get("total");
log.debug("############# Total: "+ total);
if(total == 0)
{
	log.debug("No result found");
	return;
}
sql.close();
return total as Double;

The sum holds the value properly when checked. Whenever the Table Grid field is updated for a value on Jira Edit Issue Screen, the scripted field's value on that screen is also updated properly. But when I checked logs, I could see - [onresolve.jira.groovy.GroovyCustomField] javax.script.ScriptException: java.lang.NullPointerException

Below are the log details -

2014-05-08 14:58:48,795 http-bio-8090-exec-24 ERROR admin 898x1915x3 ymn36n 0:0:0:0:0:0:0:1 /secure/IssueAction!default.jspa [onresolve.jira.groovy.GroovyCustomField] javax.script.ScriptException: java.lang.NullPointerException
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
	at javax.script.ScriptEngine$eval.call(Unknown Source)
	at com.onresolve.jira.groovy.GroovyCustomField.getValueFromIssue(GroovyCustomField.groovy:160)
	at com.atlassian.jira.issue.fields.CustomFieldImpl.getValue(CustomFieldImpl.java:404)
	at com.atlassian.jira.issue.fields.screen.StandardFieldScreenRendererFactory.getCustomFieldRenderLayoutItem(StandardFieldScreenRendererFactory.java:143)
	at com.atlassian.jira.issue.fields.screen.StandardFieldScreenRendererFactory.createFieldScreenRenderer(StandardFieldScreenRendererFactory.java:104)
	at com.atlassian.jira.issue.fields.screen.StandardFieldScreenRendererFactory.createFieldScreenRenderer(StandardFieldScreenRendererFactory.java:73)
	at com.atlassian.jira.issue.fields.screen.StandardFieldScreenRendererFactory.createFieldScreenRenderer(StandardFieldScreenRendererFactory.java:50)
	at com.atlassian.jira.issue.fields.screen.FieldScreenRendererFactoryImpl.getFieldScreenRenderer(FieldScreenRendererFactoryImpl.java:49)  <+2> (DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(DefaultComponentRegistrar.java:129)
	at com.sun.proxy.$Proxy295.getFieldScreenRenderer(Unknown Source)  <+2> (DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:154)
	at com.sun.proxy.$Proxy295.getFieldScreenRenderer(Unknown Source)
	at com.atlassian.jira.plugin.viewissue.DetailsBlockContextProvider.getContextMap(DetailsBlockContextProvider.java:164)
	at com.atlassian.plugin.web.model.AbstractWebItem.getContextMap(AbstractWebItem.java:30)
	at com.atlassian.plugin.web.model.DefaultWebLabel.getDisplayableLabel(DefaultWebLabel.java:55)
	at com.atlassian.jira.plugin.issuenav.viewissue.webpanel.WebPanelBeanBuilder.getLabel(WebPanelBeanBuilder.java:91)
	at com.atlassian.jira.plugin.issuenav.viewissue.webpanel.WebPanelBeanBuilder.builder(WebPanelBeanBuilder.java:72)
	at com.atlassian.jira.plugin.issuenav.viewissue.webpanel.WebPanelBeanBuilder.buildWithoutHtml(WebPanelBeanBuilder.java:63)
	at com.atlassian.jira.plugin.issuenav.viewissue.webpanel.WebPanelMapperUtil.mapAndRenderPanels(WebPanelMapperUtil.java:90)
	at com.atlassian.jira.plugin.issuenav.viewissue.webpanel.WebPanelMapperUtil.create(WebPanelMapperUtil.java:60)
	at com.atlassian.jira.plugin.issuenav.action.IssueAction.populateIssueFields(IssueAction.java:163)
	at com.atlassian.jira.plugin.issuenav.action.IssueAction.doDefault(IssueAction.java:132)  <+2> (DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at webwork.util.InjectionUtils$DefaultInjectionImpl.invoke(InjectionUtils.java:70)
	at webwork.util.InjectionUtils.invoke(InjectionUtils.java:56)  <+2> (ActionSupport.java:438) (ActionSupport.java:157)
	at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:87)  <+7> (DefaultInterceptorChain.java:39) (NestedInterceptorChain.java:31) (ChainedInterceptor.java:16) (DefaultInterceptorChain.java:35) (GenericDispatcher.java:225) (GenericDispatcher.java:154) (JiraWebworkActionDispatcher.java:152)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)  <+14> (ApplicationFilterChain.java:305) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XContentTypeOptionsNoSniffFilter.java:22) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (HeaderSanitisingFilter.java:44) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
	at com.idalko.jira.plugins.igrid.WebResourceIncludeFilter.doFilter(WebResourceIncludeFilter.java:157)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.jira.tzdetect.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:39)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.jira.baseurl.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:38)  <+8> (AbstractHttpFilter.java:31) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66) (ContextFilter.java:25) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(ServingRequestsFilter.java:37)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsDispatcherFilter.doFilter(PrettyUrlsDispatcherFilter.java:60)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsSiteMeshFilter.doFilter(PrettyUrlsSiteMeshFilter.java:92)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsMatcherFilter.doFilter(PrettyUrlsMatcherFilter.java:56)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.labs.botkiller.BotKillerFilter.doFilter(BotKillerFilter.java:36)  <+21> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AccessLogFilter.java:103) (AccessLogFilter.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XsrfTokenAdditionRequestFilter.java:54) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SitemeshPageFilter.java:118) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+22> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SecurityFilter.java:234) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (TrustedApplicationsFilter.java:100) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (BaseLoginFilter.java:169) (JiraLoginFilter.java:70) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66) (OAuthFilter.java:55) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+13> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ProfilingFilter.java:99) (JIRAProfilingFilter.java:19) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractJohnsonFilter.java:71) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210)
	at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
	at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
	at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)  <+10> (UrlRewriteFilter.java:394) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (GzipFilter.java:74) (GzipFilter.java:51) (JiraGzipFilter.java:55) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
	at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+41> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66) (JWDSendRedirectFilter.java:25) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractCachingFilter.java:33) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractEncodingFilter.java:41) (AbstractHttpFilter.java:31) (PathMatchingEncodingFilter.java:49) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (JiraStartupChecklistFilter.java:78) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (JiraFirstFilter.java:57) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (StandardWrapperValve.java:225) (StandardContextValve.java:123) (AuthenticatorBase.java:472) (StandardHostValve.java:168) (ErrorReportValve.java:98) (StandardEngineValve.java:118) (AccessLogValve.java:927) (CoyoteAdapter.java:407) (AbstractHttp11Processor.java:1001) (AbstractProtocol.java:585) (JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:724)
Caused by: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
	... 209 more
Caused by: java.lang.NullPointerException
	at Script1.run(Script1.groovy:23)
	... 210 more

Also, while reindexing process hangs in Jira. It needs a force restart.

It would help a lot if anybody can highlight whats going wrong with the script here.

Regards,

Naren.

1 answer

1 accepted

1 vote

I think that exception is from another custom field, it;s referring to line 23. Maybe you only posted part of it?

Also your code is bad, you don't close the connection if there is no result.

You should do it like

try {
  ... do stuff
  return result
}
finally {
  ... clean up
}

Thanks a ton @Jamie. I've corrected the code. After the changes, I am monitoring the logs and now I don't see any errors while performing the operations. Also, I am able to reindex Jira properly now :).

However, when I start Jira, the below error in Jira gets.


2014-05-09 10:57:04,706 localhost-startStop-1 INFO      [plugins.dvcs.scheduler.DvcsScheduler] DvcsScheduler start planned at Fri May 09 11:04:19 IST 2014, interval=3600000
2014-05-09 10:57:08,004 localhost-startStop-1 WARN      [onresolve.jira.groovy.ScriptManagerImpl] Error migrating listeners to new format
groovy.lang.MissingMethodException: No signature of method: org.picocontainer.defaults.DefaultPicoContainer.getComponent() is applicable for argument types: (java.lang.Class) values: [interface com.atlassian.jira.event.ListenerManager]
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at com.onresolve.jira.groovy.CannedScriptListener.<init>(CannedScriptListener.groovy:21)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

691 views 6 13
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you