Possible FP for java:S2924: @TempDir declared in super class

Hi,

the following code raises an issue on tempDir, if the member is not used in the class:

import java.nio.file.Path;
import org.junit.jupiter.api.io.TempDir;

public abstract class AbstractTestCase {

  @TempDir
  protected Path tempDir;
                 ^^^^^^^
}

The member is protected and could be used in a subclass:

import java.nio.file.Files;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class TempTest extends AbstractTestCase {

  @BeforeEach
  void setup() throws Exception {
    Files.createTempFile(tempDir, "test", "");
  }

  @Test
  void test() {

  }
}

In my opinion this is a false positive and no issue should be raised if the member is either public, protected or package-private.

We are using SonarQube 8.9.5 with SonarLint 7.3.1

Best,
Oliver

Hey there.

Make sure to read this post before raising a thread here:

Specifically, we don’t know what products you’re using (SonarQube? SonarCloud?) and what version (if relevant)

Hi Colin,

I’ve added which products we are currently using.

Hi @oliver,

Thanks for the report. We should not report on non-private rules declared inside abstract classes.

A ticket has been created to fix the FP.

Dorian