-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4238 S2924 should not report on non-private rules declared …
…inside of abstract classes (#4886)
- Loading branch information
1 parent
b3741f0
commit 0d7703c
Showing
9 changed files
with
92 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S2187.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S2187", | ||
"hasTruePositives": true, | ||
"falseNegatives": 11, | ||
"falseNegatives": 12, | ||
"falsePositives": 1 | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S2699.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S2699", | ||
"hasTruePositives": true, | ||
"falseNegatives": 150, | ||
"falseNegatives": 151, | ||
"falsePositives": 1 | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S2924.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S2924", | ||
"hasTruePositives": false, | ||
"falseNegatives": 8, | ||
"falseNegatives": 11, | ||
"falsePositives": 0 | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S3577.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S3577", | ||
"hasTruePositives": true, | ||
"falseNegatives": 45, | ||
"falseNegatives": 46, | ||
"falsePositives": 0 | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...checks-test-sources/default/src/test/java/checks/tests/UnusedTestRuleCheck_Protected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package checks.tests; | ||
|
||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
// https://community.sonarsource.com/t/possible-fp-for-java-tempdir-declared-in-super-class/60836 | ||
// https://sonarsource.atlassian.net/browse/SONARJAVA-4238 | ||
public abstract class UnusedTestRuleCheck_Protected { | ||
@TempDir | ||
protected Path tempDirOldFP; // Compliant FP as used in a subclass - compliant because not private | ||
} | ||
|
||
// Test abstract private | ||
abstract class AbstractTestCase { | ||
|
||
@TempDir | ||
private Path tempDir; // Noncompliant {{Remove this unused "TempDir".}} | ||
// increases AutoScan FNs | ||
|
||
void test() { | ||
} | ||
|
||
} | ||
|
||
// Test non-abstract private | ||
class ClassTestCase { // increases AutoScan FNs | ||
|
||
@TempDir | ||
private Path tempDir; // Noncompliant {{Remove this unused "TempDir".}} | ||
// increases AutoScan FNs | ||
|
||
void test() { | ||
} | ||
|
||
} | ||
|
||
// Test non-abstract protected | ||
class ClassTestCase2 { | ||
|
||
@TempDir | ||
protected Path tempDir; // Noncompliant {{Remove this unused "TempDir".}} | ||
// increases AutoScan FNs | ||
|
||
void test() { | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...cks-test-sources/default/src/test/java/checks/tests/UnusedTestRuleCheck_UseProtected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package checks.tests; | ||
|
||
import java.nio.file.Files; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
// AutoScan S3577 Increases FN to 46 | ||
public class UnusedTestRuleCheck_UseProtected extends UnusedTestRuleCheck_Protected { | ||
@BeforeEach | ||
void setup() throws Exception { | ||
Files.createTempFile(tempDirOldFP, "test", ""); | ||
} | ||
@Test | ||
void test() { | ||
// AutoScan S2699 Increases FN to 151 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters