Skip to content
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] UnnecessaryFullyQualifiedName: false-positive in an enum that uses its own static variables #5263

Closed
garydgregory opened this issue Oct 7, 2024 · 2 comments · Fixed by #5353
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code
Milestone

Comments

@garydgregory
Copy link

garydgregory commented Oct 7, 2024

Affects PMD Version: 7.6.0

Rule:

UnnecessaryFullyQualifiedName

Description:

Code Sample demonstrating the issue:

package org.apache.commons.io;

public enum EnumX {

    VALUE_X(EnumX.X); // MUST qualify the name or the file won't compile

    static final String X = "X";

    private final String v;

    EnumX(final String v) {
        this.v = v;
    }

    public String getV() {
        return v;
    }
}

Incorrectly generates:

<violation beginline="5" endline="5" begincolumn="13" endcolumn="18" rule="UnnecessaryFullyQualifiedName" ruleset="Code Style" package="org.apache.commons.io" class="EnumX" externalInfoUrl="https://docs.pmd-code.org/pmd-doc-7.6.0/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname" priority="4">
Unnecessary qualifier 'EnumX': 'X' is already in scope because it is declared in an enclosing type
</violation>

Expected outcome:

PMD reports a violation at line 5, but that's wrong. That's a false positive.

Running PMD through: Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)

@garydgregory garydgregory added the a:false-positive PMD flags a piece of code that is not problematic label Oct 7, 2024
@oowekyala
Copy link
Member

Thank you for the report. It seems this is also a problem with regular classes. The problem is the forward reference, which may happen in any type of class/enum/interface/etc.

@garydgregory
Copy link
Author

Hi @oowekyala

Its worth noting that in an enum, you don't have the choice but to write the code this way.

I am looking forward to a fix so I can drop all the NOPMD comments I just had to insert 😉

TY! 😄

@oowekyala oowekyala added the in:symbol-table Affects the symbol table code label Oct 8, 2024
@adangel adangel changed the title [java] False-positve UnnecessaryFullyQualifiedName in an enum that uses its own static variables [java] UnnecessaryFullyQualifiedName: false-positve in an enum that uses its own static variables Oct 11, 2024
@oowekyala oowekyala added this to the 7.8.0 milestone Nov 21, 2024
@adangel adangel changed the title [java] UnnecessaryFullyQualifiedName: false-positve in an enum that uses its own static variables [java] UnnecessaryFullyQualifiedName: false-positive in an enum that uses its own static variables Nov 22, 2024
adangel added a commit that referenced this issue Nov 22, 2024
…rences (#5353)

Merge pull request #5353 from oowekyala:issue5263-ufqn-forward-ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic in:symbol-table Affects the symbol table code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants