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 (#2161)
* 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 ([#2142](#2142)). This PR fixes this issue. * Update spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFieldSelfAssignment.java Co-authored-by: Kengo TODA <skypencil+github@gmail.com> * Update spotbugs/src/main/java/edu/umd/cs/findbugs/detect/FindFieldSelfAssignment.java Co-authored-by: Kengo TODA <skypencil+github@gmail.com> * Fixed according to the comments of @KengoTODA Co-authored-by: Kengo TODA <skypencil@gmail.com> Co-authored-by: Kengo TODA <skypencil+github@gmail.com>
- Loading branch information
1 parent
4c0c1b9
commit 7c835b6
Showing
4 changed files
with
83 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 | ||
} | ||
} | ||
} |