Uncaught ClassCastException in groovy

Jakub Cieplinski December 9, 2021

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
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2021

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 

Jakub Cieplinski December 10, 2021

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

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2021

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

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

 Fabio

Jakub Cieplinski December 10, 2021

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?

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2021

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 

Jakub Cieplinski December 10, 2021

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

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2021
Jakub Cieplinski December 12, 2021

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