redhat-developer / redhat-developer/vscode-java

Type resolution fails when namespace collision occurs between local Type and lib reference

Open
#1,785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

I have a package private enum that I reference in another class in the same package. Code underlines the enum as unresolved, because there's no import statement. As the two Types exist in the same package, no import is necessary.

The code builds fine with Maven. Also I'm able to use Code to ctrl-click jump to the enum that Code marks as unresolved.

Environment

Operating System: Windows_NT x64 10.0.19042 + WSLv2 + Ubuntu 20.10
JDK version: OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.10)
Visual Studio Code version: 1.52.1, Electron 9.3.5

  • Java extension version: v0.74.0
Steps To Reproduce

package SomePackage
public enum TypeA {
ENUM_DEF(String s);
...//private fields, constructor, etc.
public toString() { return s;}
}

package SomePackage
public TypeB() {
String enumVal = TypeA.ENUM_DEF.toString();
...
}

Code underlines TypeA as unresolved, because there are other classes in my maven classpath that are called "TypeA". If I perform an "organize import" command, I see the other types in the dropdown but I do not see my own.

If I rename my local enum to be a unique name, Code resolves it fine. Seems to be a problem with the lookup algorithm that underlines errors, because it ignores the local package.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the collision with two same-package Java types and another TypeA on the Maven classpath, then compare type resolution, organize imports, and ctrl-click navigation. Done means the local package TypeA resolves without an import while similarly named library types remain distinguishable.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.