Details

    • Number of attachments :
      0

      Description

      I think the problem is int variable when Violation.getLineId returns Integer (may be null).

      ...

      ...
      [INFO]  Execute decorators...
      [INFO] ------------------------------------------------------------------------
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] Can not execute Sonar
      ...
      
      Caused by: java.lang.NullPointerException
              at org.sonar.plugins.uselesscodetracker.decorator.ViolationsDecorator.saveFileMeasure(ViolationsDecorator.java:78)
              at org.sonar.plugins.uselesscodetracker.decorator.ViolationsDecorator.decorate(ViolationsDecorator.java:66)
              at org.sonar.batch.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:76)
              at org.sonar.batch.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:69)
              at org.sonar.batch.DecoratorsExecutor.decorateResource(DecoratorsExecutor.java:69)
              at org.sonar.batch.DecoratorsExecutor.execute(DecoratorsExecutor.java:62)
              at org.sonar.batch.ProjectBatch.execute(ProjectBatch.java:59)
              at org.sonar.batch.Batch.analyzeProject(Batch.java:113)
              at org.sonar.batch.Batch.analyzeProject(Batch.java:110)
              at org.sonar.batch.Batch.analyzeProject(Batch.java:110)
              at org.sonar.batch.Batch.analyzeProjects(Batch.java:82)
              at org.sonar.batch.Batch.execute(Batch.java:57)
              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:92)
              ... 21 more
      

        Issue Links

          Activity

          Hide
          Olivier Gaudin added a comment -

          Yep, you are correct and this is going to be easy to fix. I still cannot understand how we can get into such situation. It means that a "Unused private method" is reported without a line number and this sounds like a bug in the underlying tool. Did you activate PMD or SQUID. Can you atach a sample to reproduce ?

          Show
          Olivier Gaudin added a comment - Yep, you are correct and this is going to be easy to fix. I still cannot understand how we can get into such situation. It means that a "Unused private method" is reported without a line number and this sounds like a bug in the underlying tool. Did you activate PMD or SQUID. Can you atach a sample to reproduce ?
          Hide
          David Matejcek added a comment - - edited

          Sorry, creating and verifying a sample code can tak maybe more than a correction. Maybe later if I find some time.
          Generally line numbers can be missing if the code was compiled without -debug parameter (it is not my case, except some used libraries), or with some dynamic compilation.
          At this time I still don't know what input source exactly caused this.
          Squid: only the "Unused private method" checked. PMD is also activated.

          Show
          David Matejcek added a comment - - edited Sorry, creating and verifying a sample code can tak maybe more than a correction. Maybe later if I find some time. Generally line numbers can be missing if the code was compiled without -debug parameter (it is not my case, except some used libraries), or with some dynamic compilation. At this time I still don't know what input source exactly caused this. Squid: only the "Unused private method" checked. PMD is also activated.
          Hide
          Larry Shatzer added a comment - - edited

          This causes the problem:

           
          package org.larrys;
          
          import java.util.List;
          
          public class PrivateMethod {
            private void transactionValidation(String transaction, List<String> containers) {
            }
          }
          

          However, if I have this:

          package org.larrys;
          
          public class PrivateMethod {
            private void transactionValidation(String transaction, String container) {
            }
          }
          

          It goes through fine. So now I removed generics from the method signature, so it was:

          public class PrivateMethod {
            private void transactionValidation(String transaction, List containers) {
            }
          }
          

          And it passes.

          This is all with the Squid rule only.

          Show
          Larry Shatzer added a comment - - edited This causes the problem: package org.larrys; import java.util.List; public class PrivateMethod { private void transactionValidation(String transaction, List<String> containers) { } } However, if I have this: package org.larrys; public class PrivateMethod { private void transactionValidation(String transaction, String container) { } } It goes through fine. So now I removed generics from the method signature, so it was: public class PrivateMethod { private void transactionValidation(String transaction, List containers) { } } And it passes. This is all with the Squid rule only.
          Hide
          Larry Shatzer added a comment -

          If I disable the Squid rule for unused private methods, and use the PMD one, I do not have this problem. So this must be a bug with Squid.

          Show
          Larry Shatzer added a comment - If I disable the Squid rule for unused private methods, and use the PMD one, I do not have this problem. So this must be a bug with Squid.
          Hide
          David Matejcek added a comment -

          So maybe it is a bug in both, because certainly it is not right to use unboxing where generally can be null retrieved.

          I'm wondering what I see through Sonar (Squid: UnusedPrivateMethod):

          Unused private method : Private method '<init>(...)' is never used.
          • but there is no such method nor static initialization, only some simple private class. I don't understand it.

          So I will turn it off. Thank you very much, Larry!

          Show
          David Matejcek added a comment - So maybe it is a bug in both, because certainly it is not right to use unboxing where generally can be null retrieved. I'm wondering what I see through Sonar (Squid: UnusedPrivateMethod): Unused private method : Private method '<init>(...)' is never used. but there is no such method nor static initialization, only some simple private class. I don't understand it. So I will turn it off. Thank you very much, Larry!
          Hide
          Freddy Mallet added a comment -

          FYI, I've created SONAR-1978 to fix the Squid bug in Sonar 2.5.

          Show
          Freddy Mallet added a comment - FYI, I've created SONAR-1978 to fix the Squid bug in Sonar 2.5.

            People

            • Assignee:
              Unassigned
              Reporter:
              David Matejcek
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: