Assigning to a variable in an if/else for effective-final assignment marks the assignments as an issue under java:S1854 when the variable is then used in a lambda expression.
versions used (SonarQube, Scanner, language analyzer)
IntelliJ plugin: 4.14.2.28348
IntelliJ Idea: 2020.3.3
Here’s a screenshot of the code highlighted
Here’s a snippet of the code, the issue seems to occur when the personTypeCrmEntity
param is used in a lambda function. The collections you can see are from the Vavr library.
List<Tuple2<PersonType, CrmEntity>> personTypeCrmEntity;
if (etlConfig.getCrmEntityMap().containsKey("Lead")) {
personTypeCrmEntity = List.of(
Tuple.of(PersonType.CANDIDATE, crmEntityMap.get("Candidate")),
Tuple.of(PersonType.CLIENT_CONTACT, crmEntityMap.get("ClientContact")),
Tuple.of(PersonType.LEAD, crmEntityMap.get("Lead"))
);
} else {
personTypeCrmEntity = List.of(
Tuple.of(PersonType.CANDIDATE, crmEntityMap.get("Candidate")),
Tuple.of(PersonType.CLIENT_CONTACT, crmEntityMap.get("ClientContact"))
);
}
return new SimpleRowProcessor(
rows -> processUpsert(rows, connector, personTypeCrmEntity, crmEntityMap, mappedEntities),
rows -> processDelete(rows, crmEntityMap, mappedEntities));
I can’t share any more of this code but I could perhaps find some time to make an example project/code at some point if people can’t reproduce this issue.