Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-15959

MultiSelectCFType.getSingularObjectFromString returns incorrect object

    XMLWordPrintable

Details

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            80cc0750eb13 John Baker
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: