Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube giving unused private method issue for lambda usage

I have the following logic;

..
if(list.stream()
       .filter(MyClass::isEnabled)
       .filter(this::isActive)
       .count() > 0) {
    //do smth
}
..
private boolean isActive(MyClass obj) {
    return bool;
}

As you see, isActive method is being used in the stream structure, but when I build this class on Jenkins, I get the unused private method issue from SonarQube, it says you should delete this redundant private method. Is this a bug? If not, why haven't they still included lambda logic in their analyze structure?

Only solution is, obviously, to do this;

.filter(obj -> isActive(obj)), but it destroys the uniformity, and even the readability (imo).

like image 366
buræquete Avatar asked Feb 26 '16 03:02

buræquete


1 Answers

This is a known issue of SonarQube java analyzer : https://jira.sonarsource.com/browse/SONARJAVA-583

This is due to a lack of semantic analysis to resolve properly method reference (thus identify to which method this::isActive refers to).

like image 92
benzonico Avatar answered Oct 26 '22 13:10

benzonico