java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection

Atlassian JIRA | John Baker | 8 years ago
  1. 0

    [JRA-15959] MultiSelectCFType.getSingularObjectFromString returns incorrect object - Atlassian JIRA

    atlassian.com | 1 year ago
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
  2. 0

    I've been creating tickets with custom fields and have found some inconsistent behaviour in the getSingularObjectFromString method. My understanding is that a String is passed and it should parse/whatever the String and return a value that can be set on the field. Consider the folllowing code: Object v = customField.getCustomFieldType().getSingularObjectFromString(inputString); issueObject.setCustomFieldValue(customField, v); Map fields = new HashMap(); fields.put("issue", issueObject); GenericValue issue = ManagerFactory.getIssueManager().createIssue(reporter, fields); This works perfectly correctly when the custom field is a text or date field, but when it's a multi select then the following stack trace is produced when the ticket is created: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection at com.atlassian.jira.issue.customfields.impl.MultiSelectCFType.createValue(MultiSelectCFType.java:145) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:575) at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:85) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:869) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1265) at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:618) The problem is MultiSelectCFType.getSingularObjectFromString which returns the given String and not the given String in a list, which is what's expected by MultiSelectCFType.createValue. Therefore, simply alter the method to return a list: return Arrays.asList(s); And the problem goes away.

    Atlassian JIRA | 8 years ago | John Baker
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
  3. 0

    I've been creating tickets with custom fields and have found some inconsistent behaviour in the getSingularObjectFromString method. My understanding is that a String is passed and it should parse/whatever the String and return a value that can be set on the field. Consider the folllowing code: Object v = customField.getCustomFieldType().getSingularObjectFromString(inputString); issueObject.setCustomFieldValue(customField, v); Map fields = new HashMap(); fields.put("issue", issueObject); GenericValue issue = ManagerFactory.getIssueManager().createIssue(reporter, fields); This works perfectly correctly when the custom field is a text or date field, but when it's a multi select then the following stack trace is produced when the ticket is created: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection at com.atlassian.jira.issue.customfields.impl.MultiSelectCFType.createValue(MultiSelectCFType.java:145) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:575) at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:85) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:869) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1265) at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:618) The problem is MultiSelectCFType.getSingularObjectFromString which returns the given String and not the given String in a list, which is what's expected by MultiSelectCFType.createValue. Therefore, simply alter the method to return a list: return Arrays.asList(s); And the problem goes away.

    Atlassian JIRA | 8 years ago | John Baker
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Serialization issu

    GitHub | 3 years ago | ydeshayes
    play.api.Application$$anon$1: Execution exception[[ClassCastException: java.lang.String cannot be cast to java.util.Collection]]
  6. 0

    find with DBQuery.is() fails for collection fields with ClassCastException

    GitHub | 2 months ago | ractive
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.lang.String cannot be cast to java.util.Collection

      at com.atlassian.jira.issue.customfields.impl.MultiSelectCFType.createValue()
    2. com.atlassian.jira
      IssueCreateFunction.execute
      1. com.atlassian.jira.issue.customfields.impl.MultiSelectCFType.createValue(MultiSelectCFType.java:145)
      2. com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:575)
      3. com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:85)
      3 frames
    3. com.opensymphony.workflow
      AbstractWorkflow.initialize
      1. com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:869)
      2. com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1265)
      3. com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:618)
      3 frames