FP: S2970 with AssertJ / SoftAssertions / Field Injection

The following code produces a False Positive.

The problem is similar to [SONARJAVA-3324] FP in S2970 when using JUnit 5 Soft assertions extension. - SonarSource with one difference: in SONARJAVA-3324 the SoftAssertions instance is passed as parameter to the test method, in the following example it is injected into the test class.

@org.junit.jupiter.api.extension.ExtendWith(org.assertj.core.api.junit.jupiter.SoftAssertionsExtension.class)
class JUnit5SoftAssertionsExample {
  @org.assertj.core.api.junit.jupiter.InjectSoftAssertions
  private org.assertj.core.api.SoftAssertions softly;

  @org.junit.jupiter.api.Test
  void junit5_soft_assertions_example() {
    softly.assertThat(5).isLessThan(3);
    // No need to call softly.assertAll(), this is automatically done by the SoftAssertionsExtension
  }
}

Hey there.

What products are you using (SonarQube, SonarCloud, SonarLint) and if relevant: what versions?

Hey Colin,

I first noticed it on SonarQube Developer Edition 9.3 (Build 51899).

I can reproduce it on SonarQube Community Edition Version 9.4 (Build 54424).

Hey Colin,

any updates on this?