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

[java] SingularField false positive with non static inner classes #1688

Closed
arturbosch opened this issue Feb 21, 2019 · 0 comments
Closed

[java] SingularField false positive with non static inner classes #1688

arturbosch opened this issue Feb 21, 2019 · 0 comments
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code
Milestone

Comments

@arturbosch
Copy link

arturbosch commented Feb 21, 2019

Affects PMD Version: 6.11.0

Rule: SingularField

Description: Suggests to move the field value to local var even if it is used from an inner class instance with A.this.value.

Code Sample demonstrating the issue:

class A {

    private String value;
    private String derivedValue;

    public A(String value) {
        this.value = value;
        this.derivedValue = this.value + "-more";
    }

    private void run() {
        final B b = new B();
        b.useA();
    }

    public static void main(String[] args) {
        new A("").run();
    }

    public class B {

        public void useA() {
            final String field = A.this.value;
            System.out.println(field);
        }
    }
}

Running PMD through: CLI

@jsotuyod jsotuyod added in:symbol-table Affects the symbol table code a:bug PMD crashes or fails to analyse a file. labels Feb 22, 2019
@oowekyala oowekyala added a:false-positive PMD flags a piece of code that is not problematic and removed a:bug PMD crashes or fails to analyse a file. labels Mar 6, 2022
@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@oowekyala oowekyala added this to the 7.0.0 milestone Mar 21, 2024
oowekyala added a commit that referenced this issue Mar 21, 2024
@adangel adangel removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code
Projects
None yet
Development

No branches or pull requests

4 participants