- Operating system: Linux
- IDE name and flavor/env:
Using sonarlint as Java library via gradle:
{module = “org.sonarsource.sonarlint.core:sonarlint-core”, version = “9.8.0.76914” }
{ module = “org.sonarsource.java:sonar-java-plugin”, version = “7.31.0.34839” }
Getting a false positive for the following code:
package com;
public class MyExample {
private static List<String> getEntities(String path, Entity entity) {
List<String> entities = new ArrayList<>();
TraversalUtils.traverseWithKey(rootEntities, (path, entity) -> {
if (entity.getType() == EType.NAME) {
return false;
}
if (isFiltered(entity, path)
&& !entity.getType().endsWith(TypeNames.NAME)) {
int start = calculateStart(entity);
int end = calculateEnd(entity);
entities.add("start");
return false;
}
return true;
});
return entities;
}
}
Message is
Move the declaration of
entities
closer to the code that uses it
But that’s not possible. Seems like the lambda is not taken into account correctly.