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] false positive for UselessQualifiedThis #1372

Closed
kevin-wayne opened this Issue Oct 7, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@kevin-wayne
Copy link

kevin-wayne commented Oct 7, 2018

Affects PMD Version:
6.3

Rule:
UselessQualifiedThis, 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 doesn't use the this keyword, so the UselessQualifiedThis rule should not be relevant.

There is also a false positive for UnusedPrivateField.

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

@oowekyala

This comment has been minimized.

Copy link
Member

oowekyala commented Nov 2, 2018

The parsing for qualified this syntax appears to be very unhelpful. The .this is parsed as a primary suffix, which doesn't have a usesThisModifier method or an image, so there's no way to find that it's actually a qualified this without proceeding by elimination - which is what the rule does, and it fails here. Well at least it's easy to fix (#1427)

@oowekyala oowekyala added the has:pr label Nov 2, 2018

@oowekyala oowekyala added this to the 6.10.0 milestone Nov 2, 2018

@kevin-wayne

This comment has been minimized.

Copy link

kevin-wayne commented Nov 2, 2018

Thanks, much appreciated.

@jsotuyod

This comment has been minimized.

Copy link
Member

jsotuyod commented Nov 5, 2018

I created #1433 for the UnusedPrivateField false positive, to track it independently

@jsotuyod jsotuyod closed this in e1b5717 Nov 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment