Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An inconsistent detection result of rule SA_FIELD_SELF_ASSIGNMENT #2142

Closed
vanguard-1024 opened this issue Aug 17, 2022 · 1 comment
Closed

Comments

@vanguard-1024
Copy link

Hi, I found an inconsistent detection result about the rule SA_FIELD_SELF_ASSIGNMENT, the code example is below. SpotBugs can detect the bug in line 4, but cannot in line 8. These two lines are equivalent, hence, I think this is a false negative.

public class C {
    int foo;
    void foo1() {
        foo = foo++;  // can report a warning in this line
    }
    class subC {
        void foo2() {
            foo = foo++; // should report a warning in this line
        }
    }
}

SpotBugs version: 4.7.1

baloghadamsoftware pushed a commit to baloghadamsoftware/spotbugs that referenced this issue Sep 1, 2022
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.
@baloghadamsoftware
Copy link
Contributor

@vanguard-1024 I made a PR to fix this.

KengoTODA added a commit that referenced this issue Sep 5, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants