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

Create Issue Handler calculates priority incorrectly when number of priorities is not five

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Low
    • None
    • 2.6.1 Pro, 2.6.1 Enterprise, 3.0 Standard Beta, 3.0 Professional Beta, 3.0 Enterprise Beta, 3.0, 3.0.1, 3.0.2, 3.0.3, 3.1, 3.1.1, 3.2 Beta, 3.2, 3.2.1, 3.2.2
    • Scheduled Tasks

    Description

      The Create Issue Handler looks for an X-Priority header in the email to use when setting the priority on the issue being created, but there is a problem with the way it calculates which priority to use. The first thing to note is that the priority number it calculates is used according to the order of the priorities in JIRA, not the actual priority numbers/codes. So a value of 1 means it would select the first priority as listed/organized in JIRA, a value of 2 means it would select the second priority, etc. (regardless of what their actual number/code is).

      The calculation it performs is:
      int priorityNumber = (int) Math.ceil(((double) priorities.size() / 5d) * priorityValue);

      In the code above priorities.size() gets the number of priorities in JIRA and priorityValue is the value from the X-Priority email header. The problem is multiplying the value from the X-Priority header by (priorities.size() / 5); I don't understand the reasoning behind it and I think it's the wrong thing to do.

      The default JIRA installation has five priorities, so in that case (priorities.size() / 5) = 1 and the calculation essentially becomes priorityNumber = priorityValue. However we only have three priorities (low, medium, and high) so for us (priorities.size() / 5) = 0.6 and the calculation becomes priorityNumber = ceil(0.6 * priorityValue). This means that in order to have the first priority selected we'd set the X-Priority header to 1. So far so good. But in order to select the second priority we'd set the X-Priority header to either 2 or 3 since both ceil(1.2) and ceil(1.8) = 2, and in order to select the third priority we'd have to set the X-Priority header to either 4 or 5 since ceil(2.4) and ceil(3.0) = 3. This is extremely non-intuitive, confusing behavior and I probably wouldn't have figured this out if I wasn't able to look at the source code.

      I'd recommend either of two ways to fix this:
      1. Take the value from the X-Priority header to be the priority number (according to the order of priorities in JIRA) without multiplying it by (priorities.size() / 5). I.e. have "int priorityNumber = priorityValue;". If the X-Priority header is set to 3 the third priority should be selected.
      This has the benefit of being more backwards compatible with how things are done now, but it still relies on the order/organization of the priorities in JIRA.

      2. Take the value from the X-Priority header to be the actual priority number/code used behind the scenes by JIRA and if there is a priority with that number/code use it, otherwise use the default middle/medium priority.
      This is less backwards compatible (though it would still work fine for the priorities in the default JIRA installation) but it has the benefit of not being tied to the order/organization of the priorities, so they could be rearranged and this would still work correctly.

      We're running version 2.6.1 but the way the Create Issue Handler calculates the priority is still the same in the latest version of JIRA which is why I marked all versions from 2.6.1 to 3.2.2 as being affected. I used the following source files for reference:
      http://www.atlassian.com/software/jira/docs/v2.6.1/examples/CreateIssueHandler.java
      http://www.atlassian.com/software/jira/docs/latest/examples/CreateIssueHandler.java

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              e420bf4442cb Sean Callan-Hinsvark
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: