Copy a parsed text to a field error

Issue #536 resolved
Andrey Kiyanovsky created an issue

Hi, Fidel!

This following function doesn't make any comments: https://www.screencast.com/t/hMGffclgO

If I remove a middle string (lastAssignee) it works: https://www.screencast.com/t/XixNmmV7

Comments (22)

  1. Andrey Kiyanovsky reporter

    BTW, it's happening from itself to itself transition. Also, it seems like lastAssigneeInRole brakes other functions.

  2. Fidel Castro Armario repo owner

    Hi Andrey,

    I have tried to reproduce your problem without success. I have tried in JIRA 6.2.3 and JIRA 7.3.2 with a normal reflexive transition, and with a global reflexive transition, and in both cases function lastAssigneeInRole() is working as expected.

    Please, check your log file for errors.

    Thanks.

  3. Andrey Kiyanovsky reporter

    I've just checked - no any error messages. Here is a full post-function:

    "1: " + %{00014} + ": " + %{00016} + " Assignee" + "\n" + "2: " + projectProperty(%{00014} + ": " + %{00016} + " Assignee") + "\n" + "la: " + lastAssigneeInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) + "\n" + "du: " + defaultUserForRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) + "\n" + "us: " + toString(usersInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")))

    Here is a project parameter:

    {Construction: Site Survey Assignee=Field Team}

    "Field team" project role has one user. No one was assigned to the issue, it's just created.

  4. Andrey Kiyanovsky reporter

    In the same transition, the following post-function doesn't work

    set Assignee to:

    projectProperty(%{00014} + ": " + %{00016} + " Assignee") = null ? %{00003} : (defaultUserForRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) != null ? defaultUserForRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) : (toString(usersInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee"))) = "" ? %{00003} : nthElement(usersInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")), 1)))

    If I remove a part with defaultUserForRole - it works, it assigns the issue to the first user. There is no default user for this project role.

  5. Andrey Kiyanovsky reporter

    I think I found why the first post-function doesn't work, it doesn't like string + null expression. If I replace with the following, it works:

    "la: " + (lastAssigneeInRole(projectProperty(%{00016} + " Assignee")) = null ? "null" : lastAssigneeInRole(projectProperty(%{00016} + " Assignee")))

  6. Andrey Kiyanovsky reporter

    It's interesting because defaultUserForRole works fine, despite it also returns null value:

    "1: " + %{00014} + ": " + %{00016} + " Assignee" + "\n" + "2: " + projectProperty(%{00014} + ": " + %{00016} + " Assignee") + "\n" + "la: " + (lastAssigneeInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) != null ? lastAssigneeInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) : "") + "\n" + "du: " + defaultUserForRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")) + "\n" + "us: " + toString(usersInRole(projectProperty(%{00014} + ": " + %{00016} + " Assignee")))

    It makes the following comment:

    1: Construction: Site Survey Assignee 2: Field Team la: du: us: test-billing

  7. Andrey Kiyanovsky reporter

    It seems like I found an error: defaultUserForRole returns empty string "" instead of null when there is no default user.

  8. Andrey Kiyanovsky reporter

    It seems like I found yet another issue: when you pass to lastAssigneeInRole null value, it throws an error in logs, while defaultUserForRole throws a warning.

  9. Fidel Castro Armario repo owner

    Hi Andrey,

    Thank you this great work. I will try to solve the problems as soon as possible.

  10. Fidel Castro Armario repo owner

    Hi Andrey,

    Version 2.2.33_beta_2 has the following changes:

    • lastAssigneeInRole() returns an empty string when no user is returned. This change in behavior shouldn't cause back-compatibility problems since comparing an empty string with null returns true, i.e. "" = null returns true.
    • lastAssigneeInRole(null) now shows a controlled error message, like defaultUserForRole(null).
  11. Andrey Kiyanovsky reporter

    Have you considered that

    1. In the documentation said it should return null.
    2. lastAssigneeInRole != null will not work.

    I think it'd be better to change defaultUserForRole to return null as in documentation. What do you think?

  12. Fidel Castro Armario repo owner

    Historically the language has considered "" equivalent to null. I know it's not a good idea, but it can't be changed in order to keep back-compatibility with all the legacy code.

    lastAssigneeInRole() != null will work the same way, since "" and null is the same for comparison operators.

  13. Andrey Kiyanovsky reporter

    The same with defaultUser(), so expression "" != null is true, and it might be a problem.

  14. Fidel Castro Armario repo owner

    Hi Andrey,

    Sorry for my mistake. I had already detected the problem in the regression automated test of the plugin. You are completely right.

    lastAssigneeInRole() will keep returning null in the definitive version 2.2.33.

    I'm working in the following changes:

    • String concatenation operator + will not fail when second operand returns a null. In those cases it will behave like if it were returning an empty string.
    • I'm updating the parser's documentation, since functions userProperty(), defaultUserForRole() and leastBusyUserInRole() actually return an empty string instead of null, as it's currently stated in the documentation. I will keep the current behavior to keep back compatibility. I'm also adding automated tests in order to guarantee that any future change on this will be detected.

    I was confused by the fact that comparisons of a string field code with null in fact treat null and empty string as if it where the same thing. This is the only special treatment of null implemented by the language.

  15. Andrey Kiyanovsky reporter

    In the last sentence, you said that null and empty string are the same, but null is not equal to the empty string and comparison will return false.

    Then I need to change my algorithm for lastAssignee returning null. Please let me know if you have any beta where I can test that.

    Is it possible to have an empty string and null equal? It'd solve the issue.

  16. Fidel Castro Armario repo owner

    Hi Andrey,

    You are right, null is not the same as empty string. JIRA Workflow Toolbox 2.2.33_beta_3 is almost the version ready to be released. In this version lastAssigneeInRole() returns null when the issue has never been assigned to a user with the role.

  17. Log in to comment