Skip to content

[java] UnusedLocalVariable: false-negative with array #2130

@linusjf

Description

@linusjf

Affects PMD Version:
6.19.0

Rule:
UnusedLocalVariable

Description:
An unused array object is not flagged as unused but flagged as DU-anomaly by rule DataflowAnomalyAnalysis. Both should happen. Comment in code states that this is a TODO.

https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedLocalVariableRule.java
Code Sample demonstrating the issue:

package pmdtests;

import java.lang.reflect.Constructor;

public final class Construct {

  private Construct() {
    throw new IllegalStateException("Private constructor.");
  }

  public static void main(String... args) {
    // get all visible constructors
    Constructor<?>[] constructors = String.class.getConstructors();
  }
}

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    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