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
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 _Catworkx_ , 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')}
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?
It looks like you're new here. Sign in or register to get started.