Error Prone version
2.49.0 (error_prone_core)
Description
UnusedVariable behaves inconsistently for method references and equivalent lambda expressions. When transform(String name) is called via this::transform, Error Prone does not report name as unused. After rewriting the call site to n -> transform(n), the same parameter is flagged. Since the method body is unchanged and name is never used, the method-reference case is a false negative.
Reproducer
package demo;
import java.util.List;
import java.util.stream.Collectors;
public class TypeParameterMethodRef<T> {
// BEFORE: no UnusedVariable warning on `name`
public List<List<T>> processRef(List<String> names) {
return names.stream()
.map(this::transform)
.collect(Collectors.toList());
}
// AFTER: UnusedVariable reported on `name`
public List<List<T>> processLambda(List<String> names) {
return names.stream()
.map(n -> transform(n))
.collect(Collectors.toList());
}
private List<T> transform(String name) {
throw new UnsupportedOperationException("transform not implemented");
}
}
Actual behavior
UnusedVariable is reported only when transform is called from a lambda; the method-reference call site suppresses the warning for the same unused parameter.
Error Prone version
2.49.0 (error_prone_core)
Description
UnusedVariablebehaves inconsistently for method references and equivalent lambda expressions. Whentransform(String name)is called viathis::transform, Error Prone does not reportnameas unused. After rewriting the call site ton -> transform(n), the same parameter is flagged. Since the method body is unchanged andnameis never used, the method-reference case is a false negative.Reproducer
Actual behavior
UnusedVariableis reported only whentransformis called from a lambda; the method-reference call site suppresses the warning for the same unused parameter.