Skip to content

[java] UnusedPrivateField: false positive when field has the same name as the class #1433

@jsotuyod

Description

@jsotuyod

Affects PMD Version:

Rule:
UnusedPrivateField

Description:

False positive when instance variable is an array (or multidimensional array) with the same name as the class. While the code below doesn't follow standard Java naming conventions, it does use the field so UnusedPrivateField is irrelevant.

Code Sample demonstrating the issue:

public class Board {
    private int[] Board;

    public Board(int[] b) {
        for (int i = 0; i < b.length; i++)
            Board[i] = b[i];
    }

    public int size() {
        return Board.length;
    }
}

Running PMD through: CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions