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

Script registry throws NPE if you have unscripted web fragments

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Done
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 5.4.1
    • Fix Version/s: 5.4.11
    • Component/s: Built-in Scripts, Fragments
    • Labels:
      None
    • Sprint:
      Sprint 38 - Next
    • Critical Points:
      2

      Description

      To reproduce:

      • Create a custom web item without a condition script (the rest of the configuration can be however you want so long as it's valid).
      • Run the Script Registry

      Expected result: The web item isn't shown in the list of scripts.

      Actual result: The script registry fails with the following error:

      java.lang.NullPointerException: Cannot get property 'scripts' on null object
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry$_getFragmentsInfo_closure7.doCall(ScriptRegistry.groovy:311)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry.getFragmentsInfo(ScriptRegistry.groovy:309)
      	at com.onresolve.scriptrunner.canned.jira.admin.ScriptRegistry.doScript(ScriptRegistry.groovy:66)
      

      Why it happens: ScriptRegistry.getScriptInfo(...) returns null instead of a ConfiguredItem object if the item in question doesn't have any script associated with it. ScriptRegistry.getFragmentsInfo() doesn't expect this and tries to access the scripts property of the returned value without doing a null check, causing the NPE.

      How to solve: The simplest fix is probably to change getFragmentsInfo to use safe navigation on the scripts property: it's being used as a condition anyway so propagating the null doesn't matter. Doing it this way saves us from having to worry about breaking any contracts of getScriptInfo.

        Attachments

          Activity

            People

            Assignee:
            ahasan Ashraful Hasan [X] (Inactive)
            Reporter:
            jchoules Joanna Choules
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: