I have a listener that is functioning perfectly fine, but at times I see the below error in the logs . . Can I please know what be the reason for this & if its possible to fix it and keeping the listener executions 100%green . .
2022-03-16 08:48:54,199 INFO [runner.ScriptBindingsManager]: Team Worker
2022-03-16 08:48:54,200 INFO [runner.ScriptBindingsManager]: Test story
2022-03-16 08:48:54,200 INFO [runner.ScriptBindingsManager]:
2022-03-16 08:48:54,204 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2022-03-16 08:48:54,204 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
java.lang.NullPointerException: Cannot invoke method indexOf() on null object
at java_lang_String$indexOf$15.call(Unknown Source)
at Script18.run(Script18.groovy:45)
Hi @Aisha M
Probably for some events, an attribute is null and your code tries to get a substring of that null attribute. I think it is best to add a null check.
If you share your code, I'll try to correct the problem.
The above highlighted lines show an error on the console (but the script works fine anyway)
1ST ONE - Cannot find matching method. com.atlassian.jira.issue.Issue#setAssignee(com.atlassian.jira.user.ApplicationUs
Please check if the declared type is correct and if method exists
2ND ONE - Cannot find matching method.
com.atlassian.jira.issue.IssueManager#updateIssue(com.atlassian.jira.user.Application
com.atlassian.jira.issue.Issue,
com.atlassian.jira.event.type.EventDispatchOption, boolean).
Please check if the declared type is correct and if method exists
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
These logs are different from what you mentioned above.
The problem here is with the code belove
String userValue = cFieldValue.substring(cFieldValue.indexOf("<")+1 , cFieldValue.indexOf(">"))
The custom field value 'cFieldValue' can be null and you can't do an operation with a null value. So, you have to check if it has a null value. If you want to skip if that value is null simply put this line
if (!cFieldValue) return
String userValue = cFieldValue.substring(cFieldValue.indexOf("<")+1 , cFieldValue.indexOf(">"))
Let's fix this part first!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ohhh makes sense ! Yes, sometimes the field can be empty , it ain't a required field . . Explains why the error appears in the log now . . (Thank you !, I was completely clueless :D )
So I simply add
if (!cFieldValue) return
above the String uservalue .... line ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, however, keep in mind that it will immediately break the script. I mean it won't update the issue as it is below the script.
If that's your purpose, please go ahead and put that line.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh :( But I want to make the script function as usual but without getting the errors for the null value in the executions . . Will it be possible to do that ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I think I was unclear.
The code will work well, but if that custom field value is null, then it won't update that issue, it will just exit the code without errors. But for the other issues which have a value (other than a null value), it will update accordingly.
If you want to update the assignee as Unassigned when the custom field value has a null value, let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's what I want ! The script must ignore if the field is NULL, but must work if the field has a value :)
So, what happens to the JIRA Assignee field if the other field is null. It wont have any change right ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that's what I want ! The script must ignore if the field is NULL, but must work if the field has a value :)
then you can use that line. It works exactly this way. Since the code will terminate if the cf value is null, it won't impact the assignee field.
For the next run, if the value is not null, then it will update the assignee field accordingly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OMG ! It worked after I added your code line . . :D
The error popped up because, while testing, I created a issue without entering a value for that field. Later I updated the value and it reflected the change in the Jira Assignee field . .
So, the error was showing for the 'Issue created' part because of the null value, as the listener is enabled for the ISSUE CREATED & ISSUE UPDATED event.
Now it works perfectly fine & is all green . . yayyy !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.