S1612 should not complain if method reference is ambiguous

Versions: SonarQube Version 6.7.1 (build 35068), SonarJava: 5.4 (build 14284)

In this situation, Sonar suggests to replace the lambda by a method reference. It is however not possible since there are two methods matching: Integer.toString() and Integer.toString(int).

Set<Integer> tempSet = new HashSet<>();
tempSet.stream().filter(Objects::nonNull).map(i -> i.toString());

Sonar should not make this impossible suggestion.

Workaround would be to use the String::valueOf method reference.

Hello,

you are right that rule S1612 doesn’t handle possible ambiguity of method reference. I created ticket to fix this issue SONARJAVA-2795 .

In your concrete case one can also avoid ambiguity by using Object::toString

Thanks for reporting this issue.

A post was split to a new topic: Potential FP on S1612