squid:S1854 Dead stores should be removed - false positive with lambda expressions

(Stephen Palmer) #1

We are using
*SonarQube 6.7.4
*SonarJava 5.5

Rule squid:S1854 Dead stores should be removed is reporting what looks like a false positive in code similar to the following (wildcard and cnCompatibleWildcard are clearly used in the lambda expression but squid:S1854 is claiming they are not used and should be removed:

private SslCertificate resolveCurrentDefaultCertificate(final WebProxy webProxy) {
    final String wildcard = service.getWildCard();
    final String cnCompatibleWildcard = service.getCnCompatibleWildcard();

    return webProxy.getProject().getSslCertificates().stream()
        // only default (generated internally)
        .filter(certificate -> certificate.getDomains().stream()
        .anyMatch(name -> name.contains(wildcard) || name.contains(cnCompatibleWildcard)))
        // only without successors
        .filter(certificate -> certificate.getSuccessor() == null)


(Adam Gabryś) #2

The problem was caused by the incorrect classpath. We’ve fixed it and now the issue is closed.