Nullpointer exception is thrown while creating a subtask

Hi,

i am getting the follwing from the logs while running a script as post function for SubTask creation.

java.lang.NullPointerException: Cannot invoke method contains() on null object

at Script7.run(Script7.groovy:5)

The code used is working fine but throws exception in the logs

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.issuetype.IssueType

if ((issue.issueTypeObject.name == 'Web') || (issue.issueTypeObject.name == 'Email') || (issue.issueTypeObject.name == 'Maintenance'))  {
    if (cfValues['Translation(s)']*.value.contains("Vietnamese")) {
            IssueType issueType = ComponentAccessor.getConstantsManager().getIssueTypeObject("10903");
            for(subTask in issue.getSubTaskObjects()) {
                if(subTask.getIssueTypeObject().equals(issueType)) {
                    return false;
               }
            } 
            return true;
            }
      }

How can this be rectified?

 

Thank you!

1 answer

0 vote
Tarun Sapra Community Champion Aug 29, 2016

Hi ,

I think the list of values returned by the custom field "Translations"  can be sometimes null as well thus you should do the null check as well in order to avoid NPE

if (cfValues['Translation(s)'] && cfValues['Translation(s)']*.value.contains("Vietnamese"))

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 yesterday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

28 views 0 4
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