Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-2900

Behaviours getValue() on Linked Issues field not returning consistent object type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Done
    • High
    • Resolution: Fixed
    • 5.4.11
    • 5.4.45
    • None
    • None
    • Sprint 44
    • 1

    Description

      getFieldById("issuelinks-issues").getValue() returns String when there's only one linked issue, and returns ArrayList if there are more than one linked issue.

      The API should always return an ArrayList to be consistent.

      The reason this happens in the first place is that when the field contains multiple values, they get encoded into a single string in the front end by being concatenated with a special delimiter; the string is then sent to the back end where it is decoded by splitting on the delimiter. However, the back-end code only splits strings that contain the delimiter, so the encoding of a singleton list will not get decoded and will instead remain as a string. Possible fixes are:

      • Use a different encoding.
      • Check the field type/id on the back end to see whether it can contain multiple values, and, if it can, make sure that any singleton values get wrapped in lists.

      The workaround until this is fixed:

      def linkedIssues = getFieldById("issuelinks-issues").getValue() 
      
      // Workaround if only one linked issue is provided 
      if (linkedIssues instanceof String) linkedIssues = [ linkedIssues ]

      How to reproduce:

      Place this code

      def linkedIssues = getFieldById("issuelinks-issues").getValue()
      
      log.debug linkedIssues.class.toString()
      log.debug linkedIssues 

      On a behaviour with any issue or project with the field issuelinks-issues:

      it is important that this is placed in the field "issuelinks-issues" and not in the initialiser. 

      Add 3 values to the field, and then remove them one by one: 

      You will see the following output in the logs:

      DEBUG 2018-11-27 14:46:19,850 [jira.groovy.user.FieldBehaviours] class java.util.Arrays$ArrayList 
      DEBUG 2018-11-27 14:46:19,850 [jira.groovy.user.FieldBehaviours] [SSPA-1, SSPA-2, SSPA1]
      
      DEBUG 2018-11-27 14:46:26,342 [jira.groovy.user.FieldBehaviours] class java.util.Arrays$ArrayList 
      DEBUG 2018-11-27 14:46:26,342 [jira.groovy.user.FieldBehaviours] [SSPA-1, SSPA1] 
      
      DEBUG 2018-11-27 14:46:28,298 [jira.groovy.user.FieldBehaviours] class java.lang.String 
      DEBUG 2018-11-27 14:46:28,298 [jira.groovy.user.FieldBehaviours] SSPA-1 

      Attachments

        Activity

          People

            rholban Roland Holban [X] (Inactive)
            dyelamos Daniel Yelamos [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: