Affects Version/s: 5.4.11
Fix Version/s: 5.4.45
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:
Place this code
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: