*SonarQube 7.9.2, Scanner 5.3.0, SonarJava 6.0.2
Below code:
private Observable<CompanyUser> findInAssociatedCompany(final Company company, final String pii, final String email) {
return this.api.getEvent(a.COMPANY, companySearch, email, cs.class)
.flatMap(cs-> {
if (cs.getCompanies() == null) {
return this.action();
}
List<Company> associatedCompany = cs.getCompanies()
.stream()
.filter(someCompany -> this.findStaff(someCompany, pii).isPresent())
.collect(c.toList());
if(!associatedCompany.isEmpty()) {
return xxxxxxx;
}
return xxxxxx
});
}
Reports
“remove this unused “associatedCompany” local variable”
What is unexpected as associatedCompany is used
The same code
List<Company> associatedCompany = cs.getCompanies()
.stream()
.filter(someCompany -> this.findStaff(someCompany, pii).isPresent())
.collect(c.toList());
if(!associatedCompany.isEmpty()) {
return xxxxxxx;
}
Is placed outside of lambda function, then there is no issue reported.