Skip to content

[java] Ambiguous reference error in valid code #3763

@oowekyala

Description

@oowekyala

Affects PMD Version: 7.0.0

Make sure, to test with the latest PMD version.

Description:

Java reference resolution reports an ambiguity error where there is none, when a statically imported type shadows a java.lang member.

See https://github.com/pmd/pmd/runs/5091674249?check_suite_focus=true#step:7:9523

Exception Stacktrace:

Reference 'Exception' is ambiguous, both net.sourceforge.pmd.renderers.internal.sarif.SarifLog.Exception and java.lang.Exception match

Code Sample demonstrating the issue:

Container.java

package p;
public class Container { 
  public static class Exception {}
}

Foo.java

import static p.Container.Exception;
public class Foo {
  static {
    Exception e; // should be unambiguously p.Container.Exception 
  }
}
at Foo.java: Reference 'Exception' is ambiguous, both p.Container.Exception and java.lang.Exception match

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.in:symbol-tableAffects the symbol table code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions