SonarLint does not identify this ambiguous method call

  • Operating system: macOS Ventura 13.0.1
  • SonarLint plugin version:
  • Programming language you’re coding in: Java
  • Is connected mode used: No

Consider a class with two methods:

public void ambiguous(Consumer<String> arg) {}
public void ambiguous(Function<String, String> arg) {}

You can make simple calls like ambiguous(s -> ""), but anything else is too ambiguous for the lexer.
For example:

ambiguous(s -> System.out.println());

You would have to refactor your call to:

ambiguous(s -> {

SonarLint does not seem to understand this.
Rather it reports java:S1602 on the opening {.

My current workaround is to annotate methods with @SuppressWarnings("java:S1602").

Hey @oliveryasuna ,

First, let me thank you for your patience, and for the very precise reproducer you gave us!
We should have reacted earlier to your thread (my fault). This is indeed an FP, and we of course don’t want the sonar java rules to suggest changes that lead to non-compiling code.

I created the following ticket to fix the issue in the implementation of rule java:S1602, and avoid raising issues when curly braces are mandatory to avoid ambiguities: SONARJAVA-4539.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.