java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.opensymphony.user.User

Atlassian JIRA | Andreas Knecht | 10 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    If a multi user custom field is added to JIRA, and the custom field is added to the Assignable User permission, the Assign Issue operation breaks, when trying to gather the list of assignable Users. This is basically because our MultiUserCF is not specific enough and relies to much on the AbstractMultiCFType. The MultiUserCFType needs to override the getValueFromIssue(CustomField field, Issue issue) method to return a *Set* rather than a *List*. Or, we could make the UserCF a little more robust and make the following method able to handle more than just a Set: {code} public Set getUsers(PermissionContext ctx, String customFieldId) { if (ctx.getIssue() == null) { throw new IllegalArgumentException("PermissionContext has no issue"); } Issue issue = ctx.getIssue(); FieldManager fieldManager = ComponentManager.getInstance().getFieldManager(); CustomField field = fieldManager.getCustomField(customFieldId); CustomFieldType type = field.getCustomFieldType(); Object obj = type.getValueFromIssue(field, issue); Set users = new HashSet(1); if (obj != null) { if (obj instanceof Set) { users = (Set) obj; } else { users.add(obj); } } return users; } {code} Currently it can't, and the following exception is the result (a little further down the track, after the UserCF has added the wrong thing to the set of users): {noformat} java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.opensymphony.user.User at com.atlassian.core.user.BestNameComparator.compare(BestNameComparator.java:26) at java.util.Arrays.mergeSort(Arrays.java:1270) at java.util.Arrays.sort(Arrays.java:1210) at java.util.Collections.sort(Collections.java:159) at com.atlassian.jira.issue.fields.AssigneeSystemField.makeAssigneeOptionsList(AssigneeSystemField.java:416) at com.atlassian.jira.issue.fields.AssigneeSystemField.getAssigneeOptionsList(AssigneeSystemField.java:348) at com.atlassian.jira.issue.fields.AssigneeSystemField.getEditHtml(AssigneeSystemField.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:589) at webwork.util.InjectionUtils$DefaultInjectionImpl.invoke(InjectionUtils.java:61) at webwork.util.InjectionUtils.invoke(InjectionUtils.java:52) at webwork.util.ValueStack.findValue(ValueStack.java:426) {noformat}

    Atlassian JIRA | 10 years ago | Andreas Knecht
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.opensymphony.user.User
  2. 0

    If a multi user custom field is added to JIRA, and the custom field is added to the Assignable User permission, the Assign Issue operation breaks, when trying to gather the list of assignable Users. This is basically because our MultiUserCF is not specific enough and relies to much on the AbstractMultiCFType. The MultiUserCFType needs to override the getValueFromIssue(CustomField field, Issue issue) method to return a *Set* rather than a *List*. Or, we could make the UserCF a little more robust and make the following method able to handle more than just a Set: {code} public Set getUsers(PermissionContext ctx, String customFieldId) { if (ctx.getIssue() == null) { throw new IllegalArgumentException("PermissionContext has no issue"); } Issue issue = ctx.getIssue(); FieldManager fieldManager = ComponentManager.getInstance().getFieldManager(); CustomField field = fieldManager.getCustomField(customFieldId); CustomFieldType type = field.getCustomFieldType(); Object obj = type.getValueFromIssue(field, issue); Set users = new HashSet(1); if (obj != null) { if (obj instanceof Set) { users = (Set) obj; } else { users.add(obj); } } return users; } {code} Currently it can't, and the following exception is the result (a little further down the track, after the UserCF has added the wrong thing to the set of users): {noformat} java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.opensymphony.user.User at com.atlassian.core.user.BestNameComparator.compare(BestNameComparator.java:26) at java.util.Arrays.mergeSort(Arrays.java:1270) at java.util.Arrays.sort(Arrays.java:1210) at java.util.Collections.sort(Collections.java:159) at com.atlassian.jira.issue.fields.AssigneeSystemField.makeAssigneeOptionsList(AssigneeSystemField.java:416) at com.atlassian.jira.issue.fields.AssigneeSystemField.getAssigneeOptionsList(AssigneeSystemField.java:348) at com.atlassian.jira.issue.fields.AssigneeSystemField.getEditHtml(AssigneeSystemField.java:87) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:589) at webwork.util.InjectionUtils$DefaultInjectionImpl.invoke(InjectionUtils.java:61) at webwork.util.InjectionUtils.invoke(InjectionUtils.java:52) at webwork.util.ValueStack.findValue(ValueStack.java:426) {noformat}

    Atlassian JIRA | 10 years ago | Andreas Knecht
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.opensymphony.user.User

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.util.ArrayList cannot be cast to com.opensymphony.user.User

      at com.atlassian.core.user.BestNameComparator.compare()
    2. com.atlassian.core
      BestNameComparator.compare
      1. com.atlassian.core.user.BestNameComparator.compare(BestNameComparator.java:26)
      1 frame
    3. Java RT
      Collections.sort
      1. java.util.Arrays.mergeSort(Arrays.java:1270)
      2. java.util.Arrays.sort(Arrays.java:1210)
      3. java.util.Collections.sort(Collections.java:159)
      3 frames
    4. com.atlassian.jira
      AssigneeSystemField.getEditHtml
      1. com.atlassian.jira.issue.fields.AssigneeSystemField.makeAssigneeOptionsList(AssigneeSystemField.java:416)
      2. com.atlassian.jira.issue.fields.AssigneeSystemField.getAssigneeOptionsList(AssigneeSystemField.java:348)
      3. com.atlassian.jira.issue.fields.AssigneeSystemField.getEditHtml(AssigneeSystemField.java:87)
      3 frames
    5. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:589)
      4 frames
    6. webwork.util
      ValueStack.findValue
      1. webwork.util.InjectionUtils$DefaultInjectionImpl.invoke(InjectionUtils.java:61)
      2. webwork.util.InjectionUtils.invoke(InjectionUtils.java:52)
      3. webwork.util.ValueStack.findValue(ValueStack.java:426)
      3 frames