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

Check for null in EditIssue.initTabsWithErrors()

    XMLWordPrintable

Details

    Description

      I have developed a customfield, which adds error message not only with customfield id as key, but my own keys. (Basically I want to display an error only on a part of the customfield.)

      Unfortunately, the following code throws a NPE, as the fieldId is not a valid customfield id. This leads to null being added to tabsWithErrors, which will throw a NPE in the end:

      private void initTabsWithErrors()
      {
          tabsWithErrors = new TreeSet();
          if (getErrors() != null && !getErrors().isEmpty())
          {
              // Record the tabs which have fields with errors on them
              for (Iterator iterator = getErrors().keySet().iterator(); iterator.hasNext();)
              {
                  String fieldId = (String) iterator.next();
                  tabsWithErrors.add(getFieldScreenRenderer().getFieldScreenRenderTabPosition(fieldId));
              }
      
              // Add 1 as the status' counts in WW iterators start at 1 (not 0)
              selectedTab = ((FieldScreenRenderTab) tabsWithErrors.first()).getPosition() + 1;
      :

      We need to patch JIRA to workaround this, which is always the second best solution. The fix is trivial and side-effect free, so I hope you can include this fix soon: :-D

      private void initTabsWithErrors()
      {
          tabsWithErrors = new TreeSet();
          if (getErrors() != null && !getErrors().isEmpty())
          {
              // Record the tabs which have fields with errors on them
              for (Iterator iterator = getErrors().keySet().iterator(); iterator.hasNext();)
              {
                  String fieldId = (String) iterator.next();
                  
                  // Only add fieldScreenRenderTab if not null!
                  FieldScreenRenderTab fieldScreenRenderTab = getFieldScreenRenderer().getFieldScreenRenderTabPosition(fieldId);
                  if(fieldScreenRenderTab != null) {
                      tabsWithErrors.add(fieldScreenRenderTab);
                  }
              }
      
              // Add 1 as the status' counts in WW iterators start at 1 (not 0)
              selectedTab = ((FieldScreenRenderTab) tabsWithErrors.first()).getPosition() + 1;
      :

      Thanks!

      Attachments

        Issue Links

          Activity

            People

              jpendleton Justus Pendleton (Inactive)
              b4d715caa01f Stefan Kleineikenscheidt (K15t)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: