Details
-
Bug
-
Resolution: Obsolete
-
Low
-
3.13.1
-
Windows, Tomcat 5.5.
-
3.13
-
Description
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.