False postive with java:S5979 when using a meta-annotation

  • Sonar Qube 8.7.1 - developer edition

We are using a meta-annotation for setting up our tests which looks like this

@Tag("it")
@ActiveProfiles("it")
@ExtendWith(SpringExtension.class)
@ExtendWith(MockitoExtension.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface SetupItTest
{
}

Now applying this annotation on a test class like

@SetupItTest
class UserControllerTest {
  @Captor
  private ArgumentCaptor<String> someCaptor;
}

The rule java:S5979 will trigger because it does not parse the meta annotation and does not “see” that the class is actually annotated with @ExtendWith(MockitoExtension.class) through that annotation.

If I lift the annotation up on the test class like this, sonar will stop complaining

@ExtendWith(MockitoExtension.class)
@SetupItTest
class UserControllerTest {
  @Captor
  private ArgumentCaptor<String> someCaptor;
}

This happens since our upgrade to 8.7.0 since the rule java:S5979 was introduced there

Also, if any possible, a short hint on how to disable this rule until this gets fixed would be nice

Tried

  • admin/settings?category=exclusions
  • Under “Ignore Issues on Multiple Criteria”
    • Entered File Key Pattern: “java:S5979”
    • File Path Pattern: **/*.*

And rescanned - but the rule still has been applied. Any hints?

Hello @EugenMayer

I confirm this rule is not supporting correctly when using a meta-annotation. Ticket created: SONARJAVA-3734.

Concerning how to disable the rule, I tried what you described and it worked fine. Make sure the pattern you are using is **/*.*. (it was misformatted in your initial message, I assumed it was not expected).

Thanks for the clear description of the problem.

Best,
Quentin

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