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

Fix implementation of CustomFieldImpl.compare(Issue, Issue) method

    XMLWordPrintable

Details

    Description

      Fix implementation of CustomFieldImpl.compare(Issue, Issue) method (around line 1294)

      ...
      SortableCustomField sortable = (SortableCustomField) customFieldType;
      FieldConfig c1 = getRelevantConfig(issue1);
      FieldConfig c2 = getRelevantConfig(issue2);
      if (c1 != null && c1.equals(c2))
      {
          return sortable.compare(v1, v2, c1);
      }
      else
      {
          log.info("Sort order for custom field " + this + " for issues " + issue1 + " and " + issue2 + " " +
                  "contexts did not match. Sort order may be incorrect");
          return sortable.compare(v1, v2, c1);
      }
      ...
      

      Notice that if and else bodies are almost identical (except the extra log info message). The problem is that the contract of

      SortableCustomField.compare(Object v1, Object v2, FieldConfig fc)

      says that v1 nor v2 should be nulls. The code above does not guarantee that.

      The code should make appropriate null checks and only call compare with valid values. Also write tests that will execrise this code comprehensively.

      Attachments

        Activity

          People

            tim@atlassian.com TimP
            dushan@atlassian.com Dushan Hanuska [Atlassian]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: