Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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 for Counting how many times a bug was reopened throws null pointer exception


I've a script placed in 'post function' of 'reopen' transition to increase the counter of 'Reopen Count' field. It works sometimes but other times it throws null pointer exception 

Below is the script

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def reopenCountCf = customFieldManager.getCustomFieldObject(18906)
def reopenCount = issue.getCustomFieldValue(reopenCountCf) as Double


def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setCustomFieldValue(reopenCountCf, reopenCount)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

The error that I get is 

2021-06-07 14:12:06,115 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue E2ET-45536 for user 'xxx'. View here:
java.lang.NullPointerException: Cannot invoke method next() on null object


What is wrong with my code? 

1 answer

1 accepted

0 votes
Answer accepted
Ravi Sagar Community Leader Jun 07, 2021

Hi @Vidhya Mohan 

Does it fail when there is no value in the custom field? If yes may be you can try to add a check if the custom field value is null (empty) then instead of doing reopenCount++ just try to update the field value with 1.

I hope it works.


Hello @Ravi Sagar ,


You are right.. When the value is null it is failing. If the value is 0 or something else, then it is working correct. I'm new to groovy scripting. The script above I got it from atlassian forum. Would it be possible for you to help me with the changes that needs to be made to the script?



Suggest an answer

Log in or Sign up to answer

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