The Script Runner is throwing a java.lang.NullPointerException during indexing

Jerome Taylor February 13, 2014

This is the exception that occurs when re-indexing is started.

014-01-28 08:06:03,812 IssueIndexer:thread-3 ERROR [onresolve.jira.groovy.GroovyCustomField] javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTime() on null object

javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTime() on null object

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)

at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)

at javax.script.ScriptEngine$eval$8.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.index.indexers.impl.SortableTextCustomFieldIndexer.addDocumentFields(SortableTextCustomFieldIndexer.java:44)

at com.atlassian.jira.issue.index.indexers.impl.SortableTextCustomFieldIndexer.addDocumentFieldsSearchable(SortableTextCustomFieldIndexer.java:33)

at com.atlassian.jira.issue.index.indexers.impl.AbstractCustomFieldIndexer.addIndex(AbstractCustomFieldIndexer.java:46)

at com.atlassian.jira.issue.index.IssueDocument.getDocument(IssueDocument.java:41)

at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory.get(DefaultIssueDocumentFactory.java:15)

at com.atlassian.jira.issue.index.DefaultIssueDocumentFactory.get(DefaultIssueDocumentFactory.java:11)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$IssueLockDocumentCreationStrategy$2.get(DefaultIssueIndexer.java:606)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$IssueLockDocumentCreationStrategy$2.get(DefaultIssueIndexer.java:601)

at com.atlassian.util.concurrent.ManagedLocks$ManagedLockImpl.withLock(ManagedLocks.java:303)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$IssueLockDocumentCreationStrategy.get(DefaultIssueIndexer.java:600)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$IndexIssuesOperation.perform(DefaultIssueIndexer.java:454)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$4$1.get(DefaultIssueIndexer.java:292)

at com.atlassian.jira.issue.index.DefaultIssueIndexer$4$1.get(DefaultIssueIndexer.java:288)

at com.atlassian.jira.index.SimpleIndexingStrategy.get(SimpleIndexingStrategy.java:9)

at com.atlassian.jira.index.SimpleIndexingStrategy.get(SimpleIndexingStrategy.java:5)

at com.atlassian.jira.index.MultiThreadedIndexingStrategy$1.call(MultiThreadedIndexingStrategy.java:38)

at com.atlassian.jira.index.MultiThreadedIndexingStrategy$1.call(MultiThreadedIndexingStrategy.java:35)

at com.atlassian.jira.util.concurrent.BoundedExecutor$2.call(BoundedExecutor.java:69)

at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

at java.util.concurrent.FutureTask.run(FutureTask.java:166)

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:722)

Caused by: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTime() on null object

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)

... 27 more

Caused by: java.lang.NullPointerException: Cannot invoke method getTime() on null object

at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)

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.PogoMetaClassSite.call(PogoMetaClassSite.java:54)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)

at Script8.run(Script8.groovy:11)

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)

... 28 more

When I disabled the Script Runner plugin the problem does not occure. Here is some output from the log file atlassian-jira.log:

2014-02-11 09:03:38,985 http-bio-130.4.131.204-8443-exec-16 INFO ht1792 543x10800x1 e232kk 135.16.251.241 /rest/plugins/1.0/com.onresolve.jira.groovy.groovyrunner-key [atlassian.plugin.manager.DefaultPluginManager] Disabling com.onresolve.jira.groovy.groovyrunner

2014-02-11 09:04:25,433 JiraTaskExectionThread-2 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [action.admin.index.IndexAdminImpl] Re-indexing started

2014-02-11 09:04:25,433 JiraTaskExectionThread-2 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [jira.util.index.CompositeIndexLifecycleManager] Reindex All starting...

2014-02-11 09:04:25,434 JiraTaskExectionThread-2 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [action.admin.index.IndexAdminImpl] Re-indexing is 0% complete. Current index: Issue

2014-02-11 09:04:25,434 JiraTaskExectionThread-2 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [jira.issue.index.DefaultIndexManager] Reindexing all issues

2014-02-11 09:04:25,734 IssueIndexer:thread-1 ERROR ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [jira.issue.managers.DefaultCustomFieldManager] Could not load custom field type plugin with key 'com.atlassian.jira.plugin.linker:linker'. Is the plugin present and enabled?

2014-02-11 09:04:26,177 IssueIndexer:thread-1 ERROR ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [jira.issue.managers.DefaultCustomFieldManager] Could not load custom field type plugin with key 'com.onresolve.jira.groovy.groovyrunner:scripted-field'. Is the plugin present and enabled?

2014-02-11 09:04:26,343 IssueIndexer:thread-1 ERROR ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [jira.issue.managers.DefaultCustomFieldManager] Could not load custom field type plugin with key 'com.onresolve.jira.groovy.groovyrunner:jqlFunctionsCustomFieldType'. Is the plugin present and enabled?

2014-02-11 09:04:44,685 IssueIndexer:thread-3 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [action.admin.index.IndexAdminImpl] Re-indexing is 1% complete. Current index: Issue

2014-02-11 09:05:04,102 IssueIndexer:thread-6 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [action.admin.index.IndexAdminImpl] Re-indexing is 2% complete. Current index: Issue

2014-02-11 09:05:23,929 IssueIndexer:thread-8 INFO ht1792 544x10853x1 e232kk 135.16.251.241 /secure/admin/IndexReIndex.jspa [action.admin.index.IndexAdminImpl] Re-indexing is 3% complete. Current index: Issue

We are using JIRA 6.1.5 and Script Runner 2.1.16

2 answers

1 accepted

1 vote
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.
February 16, 2014

You have a scripted field which doesn't handle null values well. Somewhere you call getTime() on a null object. You should doublecheck your scripted field scripts.

Henning

ashok_projects May 14, 2019

Thanks for reply .. you may be right , but I'm new to the groovy can you please help me where and how to handle null pointer exception ?

 

My code snippet :

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.auth.AuthenticationContext

def authenticationContext = ComponentLocator.getComponent(AuthenticationContext)
def currentUser = authenticationContext.currentUser

def allowedUserNames = ["gmandagr", "chandram", "deepu.babu"]

mergeRequest.pullRequest.toRef.displayId.matches("feature/dev8092") &&
! (currentUser.slug in allowedUserNames)

ashok_projects May 14, 2019

Thanks for the reply, you may right but i'm new to the groovy so could you please help me how to handle the null pointer exception here in below code .

my code snippet :

import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.auth.AuthenticationContext

def authenticationContext = ComponentLocator.getComponent(AuthenticationContext)
def currentUser = authenticationContext.currentUser

def allowedUserNames = ["gmandagr", "chandram", "deepu.babu"]

mergeRequest.pullRequest.toRef.displayId.matches("feature/dev8092") &&
! (currentUser.slug in allowedUserNames)

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.
May 22, 2019

Is this Jira? In this case I think the first part should be

import com.atlassian.jira.component.ComponentAccessor 
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

What is mergeRequest?

Every reference to a function or member could be "secured" against null pointer exceptions by adding a question mark (?) before the dot (.)

So, the last line could be written

mergeRequest?.pullRequest?.toRef?.displayId?.matches("feature/dev8092") &&
! (currentUser?.username in allowedUserNames)

but in this case you would not know which object doesn't exist. If you want to know where the error comes from you could check every object.

if (mergeRequest) {

    if (mergeRequest.pullRequest) {

        // and so on...

    } else {

        log.error "pullRequest is NULL"

    }

} else {

    log.error "mergeRequest is NULL."

}
0 votes
ashok_projects May 22, 2019

Hi @Henning Tietgens ,

Could you please help me to fix the issue ?

BR

Ashok 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events