Skip to content

[java] Allow @SuppressWarnings with constants instead of literals #520

@jsotuyod

Description

@jsotuyod

Description:
PMD allows violation suppression through the @SuppressWarnings annotation, but such suppression currently only allows for a literal even when constants are valid in the Java grammar.

Edge cases (initialization on a static block with arbitrary code), or calls to static methods can't be properly resolved, but the most basic case can certainly be with the current infrastructure.

Code Sample demonstrating the issue:

public class NewClass {
    private final static String PMD_UNUSED_FORMAL_PARAMETER = "PMD.UnusedFormalParameter";

    @SuppressWarnings(PMD_UNUSED_FORMAL_PARAMETER)
    public void someMethod1(Object param) {
        System.out.println("someMethod1");
    }
}

Running PMD through: any

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions