java.lang.ClassCastException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by John Baker,
  • 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.
    via by John Baker,
    • 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)
    No Bugmate found.