Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube + Lombok configuration

I am starting a new project and I need to Use SonarQube, and I want to use Lombok, I already configured it within Eclipse and everything works fine except the static analysis.

  • Unusued private fields: When I have a @Data class, all the fields are reported as Unused private field.
  • @Getter(lazy=true): When I use this annotation I get the Redundant nullcheck of value known to be non-null see @Getter(lazy=true) (this is related to compiled code).

I think a possible solution is delombok the project, compile and run Sonar.

Similar issues in SonarQube Jira:

  • [CodeGen - Lombok] false warning hint (Unused Private Field)
  • Provide a new java rule to check for unused private field and which would support bytecode generation (cd Lombok)
  • [CodeGen - Lombok] false warning hint

(The @SuppressWarnings("PMD.UnusedPrivateField") solution don't work with latest SonarQube 4.2 )

How can I solve this problem?

like image 876
Arturo Volpe Avatar asked Jul 31 '14 13:07

Arturo Volpe


1 Answers

I asked a similar question some time ago: sonarqube 4.2 and lombok

Basically, you can't do it with annotation (like @SuppressWarnings) in the code anymore. Instead, you need to set up a (global) rule exclusion in SonarQube:

Click on Settings -> Exclusions -> Issues and adding entries in 'Ignore Issues on Multiple Criteria' section, and enter something like:

Rule Key Pattern  File Path Pattern
squid:S1068       **/models/**/*.java

It makes your source code a little bit cleaner (since you don't need @SuppressWarnings anymore), but I don't like the idea of setting global rules, as it may cause other problems.


Update:

For 'Redundant nullcheck of value known to be non-null', you can add something like following:

Rule Key Pattern                                   File Path Pattern
findbugs:RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE  **/xxxxx.java

And another one that may (or may not) be useful for you:

Rule Key Pattern                        File Path Pattern
common-java:InsufficientBranchCoverage  **/models/**/*.java 
like image 164
su- Avatar answered Sep 28 '22 05:09

su-