SonarQube Plugins
  1. SonarQube Plugins
  2. SONARPLUGINS-925

NullPointerException when CheckStyle rule has default value

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: TAGLIST-1.0
    • Fix Version/s: TAGLIST-1.1
    • Component/s: TagList
    • Labels:
      None
    • Number of attachments :
      0

      Description

      When the TodoComment CheckStyle rule has its format parameter set to default (empty = "TODO:") we get a NullPointerException. This can be fixed by explicitly setting a value.

      Caused by: java.lang.NullPointerException
             at java.util.TreeMap.getEntry(TreeMap.java:324)
             at java.util.TreeMap.get(TreeMap.java:255)
             at org.apache.commons.collections.bag.AbstractMapBag.add(AbstractMapBag.java:257)
             at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:65)
             at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:79)
             at org.sonar.plugins.taglist.ViolationsDecorator.saveFileMeasures(ViolationsDecorator.java:98)
             at org.sonar.plugins.taglist.ViolationsDecorator.decorate(ViolationsDecorator.java:76)
             at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:83)
             at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:75)
             at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:75)
             at org.sonar.batch.phases.DecoratorsExecutor.execute(DecoratorsExecutor.java:66)
             at org.sonar.batch.phases.Phases.execute(Phases.java:73)
             at org.sonar.batch.ProjectBatch.execute(ProjectBatch.java:61)
             at org.sonar.batch.Batch.analyzeModule(Batch.java:149)
             at org.sonar.batch.Batch.analyzeModules(Batch.java:106)
             at org.sonar.batch.Batch.execute(Batch.java:66)
             at org.sonar.maven.SonarMojo.executeBatch(SonarMojo.java:142)
             at org.sonar.maven.SonarMojo.execute(SonarMojo.java:133)
             at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
             at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98)
             ... 21 more
      

        Issue Links

          Activity

          Hide
          Etienne Jouvin added a comment -

          Hello.

          I add the problem also. I could fix it with modification in the JAVA source code.
          I add some "TODO:", or "TODO," ....
          By removing ":" or "," no more NullPointer.

          Regards.

          Etienne Jouvin
          www.amexio.fr

          Show
          Etienne Jouvin added a comment - Hello. I add the problem also. I could fix it with modification in the JAVA source code. I add some "TODO:", or "TODO," .... By removing ":" or "," no more NullPointer. Regards. Etienne Jouvin www.amexio.fr
          Hide
          Martin added a comment -

          Here's my stack... I guess that there is no null check on the DistributionBuilder value object prior to inserting it into commons collections, hence the NPE. I took a quick look at the code, but could not identify the appropriate level at which one would implement the null-check, or what an approriate default value would be (empty string perhaps?).

          Caused by: org.sonar.api.utils.SonarException: Fail to decorate 'myclass'
          
                  at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:84)
                  at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:70)
                  at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63)
                  at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63)
                  at org.sonar.batch.phases.DecoratorsExecutor.execute(DecoratorsExecutor.java:55)
                  at org.sonar.batch.phases.Phases.execute(Phases.java:94)
                  at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143)
                  at org.sonar.batch.bootstrap.Module.start(Module.java:83)
                  at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:111)
                  at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:101)
                  at org.sonar.batch.bootstrap.Module.start(Module.java:83)
                  at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:102)
                  at org.sonar.batch.bootstrap.Module.start(Module.java:83)
                  at org.sonar.batch.Batch.execute(Batch.java:100)
                  at org.sonar.maven3.SonarMojo.executeBatch(SonarMojo.java:146)
                  at org.sonar.maven3.SonarMojo.execute(SonarMojo.java:136)
                  at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:113)
                  ... 23 more
          Caused by: java.lang.NullPointerException
                  at java.util.TreeMap.getEntry(TreeMap.java:324)
                  at java.util.TreeMap.get(TreeMap.java:255)
                  at org.apache.commons.collections.bag.AbstractMapBag.add(AbstractMapBag.java:257)
                  at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:65)
                  at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:79)
                  at org.sonar.plugins.taglist.ViolationsDecorator.saveFileMeasures(ViolationsDecorator.java:98)
                  at org.sonar.plugins.taglist.ViolationsDecorator.decorate(ViolationsDecorator.java:76)
                  at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:79)
                  ... 39 more
          
          Show
          Martin added a comment - Here's my stack... I guess that there is no null check on the DistributionBuilder value object prior to inserting it into commons collections, hence the NPE. I took a quick look at the code, but could not identify the appropriate level at which one would implement the null-check, or what an approriate default value would be (empty string perhaps?). Caused by: org.sonar.api.utils.SonarException: Fail to decorate 'myclass' at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:84) at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:70) at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63) at org.sonar.batch.phases.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:63) at org.sonar.batch.phases.DecoratorsExecutor.execute(DecoratorsExecutor.java:55) at org.sonar.batch.phases.Phases.execute(Phases.java:94) at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:111) at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:101) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:102) at org.sonar.batch.bootstrap.Module.start(Module.java:83) at org.sonar.batch.Batch.execute(Batch.java:100) at org.sonar.maven3.SonarMojo.executeBatch(SonarMojo.java:146) at org.sonar.maven3.SonarMojo.execute(SonarMojo.java:136) at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:113) ... 23 more Caused by: java.lang.NullPointerException at java.util.TreeMap.getEntry(TreeMap.java:324) at java.util.TreeMap.get(TreeMap.java:255) at org.apache.commons.collections.bag.AbstractMapBag.add(AbstractMapBag.java:257) at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:65) at org.sonar.api.measures.CountDistributionBuilder.add(CountDistributionBuilder.java:79) at org.sonar.plugins.taglist.ViolationsDecorator.saveFileMeasures(ViolationsDecorator.java:98) at org.sonar.plugins.taglist.ViolationsDecorator.decorate(ViolationsDecorator.java:76) at org.sonar.batch.phases.DecoratorsExecutor.executeDecorator(DecoratorsExecutor.java:79) ... 39 more
          Hide
          Dariusz Dziadek added a comment -

          It seems to be simple fix. Sonar (Checkstyle) uses com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck value as key for Checkstyle's TodoComment rule (look at Useage & Installation screen or Sorar config backup XML file).
          So:

          • in ViolationsDecorator.java, line 42: replace CHECKSTYLE_RULE_CONFIG_KEY value with com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck (instead of Checker/TreeWalker/TodoComment)
          • build and install plugin

          Works for me (e.g. with FIXME[:]|TODO[:]|XXX[:]* pattern).

          Show
          Dariusz Dziadek added a comment - It seems to be simple fix. Sonar (Checkstyle) uses com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck value as key for Checkstyle's TodoComment rule (look at Useage & Installation screen or Sorar config backup XML file). So: in ViolationsDecorator.java, line 42: replace CHECKSTYLE_RULE_CONFIG_KEY value with com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck (instead of Checker/TreeWalker/TodoComment) build and install plugin Works for me (e.g. with FIXME [:] |TODO [:] |XXX [:] * pattern).

            People

            • Assignee:
              Unassigned
              Reporter:
              Lars Francke
            • Votes:
              18 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

              • Created:
                Updated: