Skip to content

[java] RedundantFieldInitializer FN with constant expressions #3684

@Zustin

Description

@Zustin

Affects PMD Version:6.41.0

Rule:RedundantFieldInitializer

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

Description:
Hi, I found a false negative about the rule RedundantFieldInitializer.

Code Sample demonstrating the issue:

class Impl {
    int a = 1 + 0 - 1; // should report a warning
    int b = 0 + 1 - 1; // can be detected
}

Expected outcome:

PMD should report a violation at line 2, but doesn't. This is a false-negative.

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions