Cast Exception

Özerk Dolanbay January 22, 2014

Hi all,

After upgrading jira from 5.2.9 to 6.1.5, some groovy scripts does not work. In the log records, there is a cast exception as "Cannot cast object 'my user object' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User'

Is there any suggestions?

1 answer

1 accepted

2 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2014

You can use the ApplicationUsers class to convert between User and ApplicationUser.

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2014
Özerk Dolanbay January 22, 2014

Thank you Henning, now it is clear. I get values from custom fields which contain users and use "User" object for return values. However, according to the document you shared above it says:

  • If you read values from CustomFields containing Users. In older versions CustomFieldsused to return User object, in 6.0 JIRA returns ApplicationUser. As in 6.0 these types are totally incompatible, you will probably get an exception:

    java.lang.ClassCastException: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to com.atlassian.crowd.embedded.api.User

So, I add "import com.atlassian.jira.user.ApplicationUsers" line in script code and use toDirectoryUser(ApplicationUser user) method to convert ApplicationUser to User.

Am I right?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2014

Yes, if the following method needs an ApplicationUser.

Özerk Dolanbay January 23, 2014

Yes, I need to convert ApplicationUser to User object so I use toDirectoryUsers method of ApplicationUsers class which accepts an ApplicationUser object.

My ex-code:

Collection<User> users = (Collection) issue.getCustomFieldValue(releatedPeopleCf)//relatedPeopleCf is a multi user picker cf

New code:

Collection<User> users = (Collection) ApplicationUsers.toDirectoryUsers(issue.getCustomFieldValue(relatedPeopleCf))

This is the correct usage, isnt it?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2014

Looks good to me :-)

Özerk Dolanbay January 23, 2014

Thanks for kindly help Henning, it is ok now ;)

Suggest an answer

Log in or Sign up to answer