- versions used (SonarQube, Scanner, language analyzer)
sonar maven plugin 3.7.0.1746
sonarqube 8.4.2.36762 - minimal code sample to reproduce (with analysis parameter, and potential instructions to compile).
import java.util.Map;
import java.util.function.IntFunction;
public class UnusedMethod {
private static final IntFunction<String> NO_OP = n -> "";
private final Map<String, IntFunction<String>> functions = Map.of("key", input -> method(input));
public String result(String key, Integer input) {
return functions.getOrDefault(key, NO_OP).apply(input);
}
private String method(Double input) {
return input.toString();
}
private String method(Integer input) {
return method(input.doubleValue());
}
}
Hello,
In the example above sonar reports that String method(Integer input) is unused and should be removed, although the method is called from within the lambda expression in the map.
If the lambda is replaced with method reference, or the methods use primitives as parameters then the issue does not appear.
Thank you for your time.