False positive on java:S6073

Hi SonarLint & Language team,

Found a false positive on rule S6073 - Mockito argument matchers should be used on all parameters

An issue is raised by this rule when I use an argument matcher defined in another method, example:

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;

public void dummyTest() {
   given(dummyClass.findAll(eqCollection(1L), eq(17))).willReturn(emptyList())

private Collection<Long> eqCollection(Long... items) {
   argThat( c -> c.size() == items.length() && c.containsAll(asList(items)))

With the message Add an eq() argument matcher on this parameter
on the line

given(dummyClass.findAll(eqCollection(1L), eq(17))).willReturn(emptyList())

Looks like my method eqCollection is not recognized as an argumentMatcher


  • SonarLint for IntelliJ version
  • Java Code analyzer version
  • Java 15.0.2

With :heart:


Hey @Xav,

Thank you for reporting the issue. There is indeed an issue with the current implementation of the rule as it only checks the return type of the method invoked and not the actual value.
To suppress the noise, the rule has been moved out of the SonarWay profile and a ticket has been created to handle it.




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