简体   繁体   中英

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).

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM