Skip to content

[java] PrematureDeclaration false positive for unused variables #3221

@adangel

Description

@adangel

Affects PMD Version: 6.33.0

Rule: PrematureDeclaration

Description:

Don't report variables that are not used at all. Those should be left to UnusedLocalVariable.

Code Sample demonstrating the issue:

public String wrongEscapeSequences() 
    {
        final String r1 = "\u0008"; // unused var - not a premature declaration
        return "\u000csssdfsd";
    }

(from https://github.com/checkstyle/checkstyle/blob/checkstyle-8.10/src/it/resources/com/google/checkstyle/test/chapter2filebasic/rule232specialescape/InputIllegalTokenText.java#L17)

Expected outcome:

  • Does PMD report a violation, where there shouldn't be one? -> false-positive

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions