Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-9116

Doesn't handle group matches that are null

XMLWordPrintable

      If my regex is:

      ^URL: (\S)+( .*)?$

      And my replacement text is:

      <a href="\1">My URL\2</a>

      It is possible that the regex can succeed and the matcher.group(2) will be null. If that happens the description setter fails like this:

      ERROR: Publisher hudson.plugins.descriptionsetter.DescriptionSetterPublisher aborted due to exception
      java.lang.NullPointerException
      at java.lang.String.replace(String.java:2208)
      at hudson.plugins.descriptionsetter.DescriptionSetterPublisher.getExpandedDescription(DescriptionSetterPublisher.java:158)
      at hudson.plugins.descriptionsetter.DescriptionSetterPublisher.perform(DescriptionSetterPublisher.java:80)
      at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
      at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:644)
      at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:623)
      at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:601)
      at hudson.model.Build$RunnerImpl.post2(Build.java:159)
      at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:570)
      at hudson.model.Run.run(Run.java:1386)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
      at hudson.model.ResourceController.execute(ResourceController.java:88)
      at hudson.model.Executor.run(Executor.java:145)

      This can probably be fixed by changing:

      result = result.replace("
      " + i, matcher.group)

      to

      result = result.replace("
      " + i, matcher.group == null ? '' : matcher.group)

      But I haven't actually checked it.

            huybrechts huybrechts
            pgweiss pgweiss
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: