forked from spotbugs/spotbugs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report bug
SA_FIELD_SELF_ASSIGNMENT
in nested classes as well
Bug `SA_FIELD_SELF_ASSIGNMENT` was not reported in nested classes, only in the outer class. This lead to inconsistent behavior. See issue ([spotbugs#2142](spotbugs#2142)). This PR fixes this issue.
- Loading branch information
Ádám Balogh
committed
Sep 1, 2022
1 parent
bfe835a
commit aad527f
Showing
4 changed files
with
81 additions
and
2 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
38 changes: 38 additions & 0 deletions
38
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2142Test.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,38 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import org.junit.Test; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class Issue2142Test extends AbstractIntegrationTest { | ||
@Test | ||
public void test() { | ||
performAnalysis("ghIssues/Issue2142.class", | ||
"ghIssues/Issue2142$Inner.class"); | ||
BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() | ||
.bugType("SA_FIELD_SELF_ASSIGNMENT").build(); | ||
assertThat(getBugCollection(), containsExactly(2, matcher)); | ||
|
||
matcher = new BugInstanceMatcherBuilder() | ||
.bugType("SA_FIELD_SELF_ASSIGNMENT") | ||
.inClass("Issue2142") | ||
.inMethod("foo1") | ||
.atLine(6) | ||
.build(); | ||
assertThat(getBugCollection(), hasItem(matcher)); | ||
|
||
matcher = new BugInstanceMatcherBuilder() | ||
.bugType("SA_FIELD_SELF_ASSIGNMENT") | ||
.inClass("Issue2142$Inner") | ||
.inMethod("foo2") | ||
.atLine(10) | ||
.build(); | ||
assertThat(getBugCollection(), hasItem(matcher)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ghIssues; | ||
|
||
public class Issue2142 { | ||
int foo; | ||
void foo1() { | ||
foo = foo++; // can report a warning in this line | ||
} | ||
class Inner { | ||
void foo2() { | ||
foo = foo++; // should report a warning in this line | ||
} | ||
} | ||
} |