Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Uncaught ClassCastException in groovy

I'm trying to write wrappers on Jira API functions with exception handling.

 

void setField(String field, value, MutableIssue issue = this.issue) {

def cfo = cfm.getCustomFieldObject(field)

try {
issue.setCustomFieldValue(cfo, value)

} catch (e) {
LOG.error('Test')
}

I purposefully try to insert wrong type of value into given customfield to trigger an exception. And it does

Caught exception while attempting to perform action 181 from workflow 1081660 on issue 'xxx'

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.util.Collection (java.lang.Integer and java.util.Collection are in module java.base of loader 'bootstrap')

However it is not being caught by the try-catch block. Why is that? Code is in groovy

1 answer

0 votes

Hi @Jakub Cieplinski ,

 

based on the error it seems that you are trying to put and integer to a collection custom field (it could be a selectlist, versions, components field).

You should set field value based on the field type (double for Numeric field, String for text field, Option for single selectlist, Collection<Option> for multiselect, Collection<Version> for version field and so on).

 

Hope this helps,

Fabio 

Hi @Fabio Racobaldo _Herzum_ , yes I'm aware of that. As I said I'm doing it on purpose to explicitly trigger that exception because I want to be able to handle it in try-catch block. But it ignores my catch and I would like to know why it does that

Try using the ClassCastException provided by (java.lang) in the catch block :

} catch (ClassCastException e) {
LOG.error('Test')
}

 Fabio

It didn't help. Although I just went through log message once again and realized it said 

Caught exception while attempting to perform action 

So it seems to me like Jira itself catches this exception before I can. I suppose this cannot be circumvented?

What log file are you checking? How do you add your code to jira (addon, scriptrunner)?

Did you add your class to logging and profiling?

In order to provide you help, we need to have all information.

Ciao,

Fabio 

I'm using scriptrunner app and checking atlassian-jira.log in jira-home/log

Class calls are triggered by intermediate script added as a post function to ticket transition

I'm not familiar with adding my classes to logging and profiling

Hi, I'm using the scriptrunner logging implementation which works fine. The logging code in catch statement is not executed because the exception is not caught by my class but by some java code inside jira

 

Caught exception while attempting to perform action 181 from workflow 1081660 on issue 'xxx'

java.lang.ClassCastException:

I want to know if this can be somehow circumvented so Jira passes those exceptions further so I can handle them myself

Suggest an answer

Log in or Sign up to answer
TAGS

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