A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5858 below:

[java] FinalFieldCouldBeStatic false positive for array initializers · Issue #5858 · pmd/pmd · GitHub

Affects PMD Version:
7.11 to 7.15 (current)

Rule:

Please provide the rule name and a link to the rule documentation:
FinalFieldCouldBeStatic

Description:
Suggesting that final fields of array type should be static is generally wrong, unless we also check that there are no mutations.
This is correctly ensured for final double coordinates = new double[]{0, 0} but not final double coordinates = {0, 0}.

Code Sample demonstrating the issue:

public class Point {
final double coordinates = {0, 0};

public void setCoordinate(int index, double value) {
coordinates[index] = value;
}

Expected outcome:

PMD reports a violation at line final double coordinates = new double[]{ 0, 0}, but that's wrong.

Running PMD through:

Gradle

Notes
This behavior changed in 4cf51a6 as part of #5553.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4