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.
@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
:
(The @SuppressWarnings("PMD.UnusedPrivateField")
solution don't work with latest SonarQube 4.2
)
How can I solve this problem?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With