Search code examples
javalambdasonarlintfalse-positivemethod-parameters

Unused method parameters should be removed (squid:S1172) false positive using lambda


I have a working method that uses parameter as a lambda expression

private BiConsumer<List<String>, Properties> handleList(Properties p) {
    return (list, prop) -> executeSubList(list, prop);
}

For p I'm getting a false positive warning from SonarLint

Unused method parameters should be removed (squid:S1172)

If I change prop to p I'm getting a compile error

Lambda expression's parameter p cannot redeclare another local variable defined in an enclosing scope

Is there a real issue or is it a false positive check when using a method parameter as a lambda parameter?


Solution

  • The issue is real. This method returns a BiConsumer that runs executeSubList on a pair or List<String> and Properties arguments, but does so regardless of p. You could just remove it:

    private BiConsumer<List<String>, Properties> handleList() {
        // p was never used, and can just be removed -------^
        return (list, prop) -> executeSubList(list, prop);
    }