False positive for "Squid:S2970 Add a call to 'assertAll' after all 'assertThat'" when using SoftAssertions.assertSoftly

This rule incorrectly warns that ‘assertAll’ needs to be called for AssertJ assertions in this example. Note that the static method SoftAssertions.assertSoftly calls the ‘assertAll()’ method.

I am seeing the false positive in both SonarQube version 6.7.6 and also when using the IntelliJ SonarLint plugin version 4.0.2.3009.

Here is a very simple example:

import org.assertj.core.api.SoftAssertions;
import org.junit.Test;

public class FalsePositiveTest {

  @Test
  public void falsePositive() {
    SoftAssertions.assertSoftly(softly -> {
      softly.assertThat(true).isTrue();
      softly.assertThat(false).isFalse();
    });
  } // The violation is marked here since it apparently doesn't know 'assertAll()' was called
}
1 Like

Hello Jeffrey,

Thank you for reporting this.
Indeed, the SoftAssertions#assertSoftly method is not handled correctly by our plugin.
I’ve created the following ticket related to this issue: SONARJAVA-3143.

Kind regards,
-Chris

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