SonarQube False Positive for Mockito Mocking Parameterised Type

  • SonarQube for IDE (IntelliJ Plugin) v12.5.0.84934
  • SonarQube is deployed with the IDE
  • IntelliJ IDEA 2026.1.4 (MacOS)

I want my source code to pass with zero SonarQube based warnings/errors. When I have code that has the following Mockito expression (for example):

final var mock = Mockito.<Pageable<DTO>>mock();

I am prompted with SonarQube rule java:S8924: This rule raises an issue when Mockito core methods are called with the Mockito. prefix instead of being statically imported.

This is a false positive as using the Mockito. prefix is required when mocking parameterised types. It cannot be replaced with a static import in Java 25.

Hi @osmundf,

Thanks for reporting this false positive!

I was able to reproduce it with the code you provided. I have created a ticket SONARJAVA-6637 to track the fix.

In the meantime, you can get rid of the issue by dropping var and explicitly typing the variable:

final Pageable<DTO> mock = mock();

Thank you again for the report and helping us improve the rule.

Noémie

Thank you. The alternative option to use an explicit type declaration is actually a valid option. Looking forward to seeing the fix in the future.