Skip to content

[java] FinalFieldCouldBeStatic false positive with non-static synchronized block (regression in 6.48, worked with 6.47) #4090

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

Closed
hgschmie opened this issue Aug 10, 2022 · 0 comments · Fixed by #4134
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@hgschmie
Copy link
Contributor

hgschmie commented Aug 10, 2022

Affects PMD Version: 6.48

Rule: FinalFieldCouldBeStatic

Please provide the rule name and a link to the rule documentation: https://pmd.github.io/latest/pmd_rules_java_design.html#finalfieldcouldbestatic

Description:

6.48 flags objects that are only used for synchronization incorrectly

Code Sample demonstrating the issue:

class foo {
    private final Object[] lock = new Object[0];

    void init() {
        synchronized (lock) {
            // do init stuff
        }
    }

    public void close() {
        synchronized (lock) {
           // do close stuff
        }
    }
}

Expected outcome: Class passes PMD checks

PMD reports a violation at line 2 ..., but that's wrong. That's a false positive.

Running PMD through: [Maven]

@hgschmie hgschmie added the a:false-positive PMD flags a piece of code that is not problematic label Aug 10, 2022
@adangel adangel added this to the 6.50.0 milestone Aug 30, 2022
@adangel adangel self-assigned this Aug 30, 2022
@adangel adangel changed the title [java] False positive with 6.48 - FinalFieldCouldBeStatic (worked with 6.47) [java] FinalFieldCouldBeStatic false positive synchronized block (regression in 6.48, worked with 6.47) Sep 26, 2022
@adangel adangel changed the title [java] FinalFieldCouldBeStatic false positive synchronized block (regression in 6.48, worked with 6.47) [java] FinalFieldCouldBeStatic false positive with non-static usages (regression in 6.48, worked with 6.47) Sep 26, 2022
@adangel adangel changed the title [java] FinalFieldCouldBeStatic false positive with non-static usages (regression in 6.48, worked with 6.47) [java] FinalFieldCouldBeStatic false positive with non-static synchronized block (regression in 6.48, worked with 6.47) Sep 26, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants