SonarQube issue with Java rule S6073

  • versions used (SonarQube, Scanner, language analyzer):
    SonarQube 9.1

SonarLint 5.1.0.34721 connected to SonarQube does NOT show the issue

  • minimal code sample to reproduce (with analysis parameter, and potential instructions to compile):
    ‘’‘Mockito.verify(Test.this.someInstance).someMethod(Test.this.someCaptor.capture(), eq(someValue));’’’

SonarQube complains about someCaptor.capture() needing an “eq” argument matcher:
“Add an “eq()” argument matcher on this parameter.”
Seems like removing “Test.this” from both the instance and the captor “solves” the issue

Hello @rporta-cc

I stumbled into this old topic and decided to have a closer look.

I did not manage to reproduce the issue on the current version of the Java analyzer.
However, I had to guess what the full code looked like, and came up with:

import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import static org.mockito.ArgumentMatchers.eq;

class MyTest {
  private Foo someInstance;
  private ArgumentCaptor<String> someCaptor;

  @Test
  void nonCompliant() {
    Mockito.verify(MyTest.this.someInstance).f(MyTest.this.someCaptor.capture(), eq("someValue"));
  }

  static class Foo {
    String f(Object a, Object b) {
      return "hi";
    }
  }
}

If you are still facing the issue, could you confirm that your code looks something like this?

In addition, you might want to check the content of the analysis logs to see if there is nothing related to unresolved imports/types, it might be the cause of this false positive.

Best,
Quentin