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] LocalVariableCouldBeFinal shouldn't report unused variables #4511

Closed
adangel opened this issue Apr 27, 2023 · 0 comments · Fixed by #4501
Closed

[java] LocalVariableCouldBeFinal shouldn't report unused variables #4511

adangel opened this issue Apr 27, 2023 · 0 comments · Fixed by #4501
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@adangel
Copy link
Member

adangel commented Apr 27, 2023

Affects PMD Version: 6.x

Rule: LocalVariableCouldBeFinal

Description:

A local variable, that is just defined but not used, is a different problem: UnusedLocalVariable. Make the variable final doesn't fix anything.

Found via #3123. It's already fixed with PMD 7.0.0-rc1.
Was fixed via #3113.

Code Sample demonstrating the issue:

public class Foo {
    public void test1() {
        int a = 0; // not final, but also not used
    }
}

Expected outcome:

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

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.

1 participant