Affects PMD Version:
6.22.0+
7.0.0
Rule: FinalFieldCouldBeStatic
Description:
FinalFieldCouldBeStatic can not detect that the right side of the assignment is not a literal, but an expression (such as: Math.PI * 0.5).
This rule is implemented through xpath search:
<![CDATA[
//FieldDeclaration
[@Final='true' and @Static='false']
/VariableDeclarator/VariableInitializer/Expression
/PrimaryExpression[not(PrimarySuffix)]/PrimaryPrefix/Literal
]]>
Code Sample demonstrating the issue:
private final double HALF_PI = Math.PI * 0.5
Expected outcome:
false-negative
Running PMD through:
CLI
Affects PMD Version:
6.22.0+
7.0.0
Rule: FinalFieldCouldBeStatic
Description:
FinalFieldCouldBeStatic can not detect that the right side of the assignment is not a literal, but an expression (such as: Math.PI * 0.5).
This rule is implemented through xpath search:
Code Sample demonstrating the issue:
Expected outcome:
false-negative
Running PMD through:
CLI