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] UnusedAssignment false positive in record compact constructor #4603

Closed
kdebski85 opened this issue Jun 23, 2023 · 0 comments · Fixed by #4839
Closed

[java] UnusedAssignment false positive in record compact constructor #4603

kdebski85 opened this issue Jun 23, 2023 · 0 comments · Fixed by #4839
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@kdebski85
Copy link
Contributor

kdebski85 commented Jun 23, 2023

Affects PMD Version: 7.0.0-rc3 (works fine in 6.55.0)

Rule: UnusedAssignment

Description:

False-positive is reported when a variable is assigned in record compact constructor.

 UnusedAssignment:       The value assigned to variable 'foo' is never used

Code Sample demonstrating the issue:

class Main {
    public static void main(String[] args) {
        System.out.println(new TestRecord(2).foo());
    }
}

record TestRecord(int foo) {
    TestRecord {
        foo = Math.min(foo, 1); // <!--- violation here
    }
}

Expected outcome:

PMD should not report false-positive about unused foo in compact constructor.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Gradle

@kdebski85 kdebski85 added the a:false-positive PMD flags a piece of code that is not problematic label Jun 23, 2023
@oowekyala oowekyala self-assigned this Jun 23, 2023
@oowekyala oowekyala added this to the 7.0.0 milestone Jun 23, 2023
@adangel adangel changed the title [java] UnusedAssignment in record compact constructor - 7.0.0-rc3 [java] UnusedAssignment false positive in record compact constructor Feb 29, 2024
adangel added a commit to adangel/pmd that referenced this issue Feb 29, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants