redhat-developer / redhat-developer/vscode-java
Organize imports removes valid imports in Java files with compile errors
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 546
- Avg merge
- 20h 1m
- Merged PRs (30d)
- 11
Description
Organize imports will remove imports when the references are not valid Java code anymore. This might remove "valid" imports that just happen to be unused at that moment, because there is a compile error before the reference. The references cannot be easily restored once the compile errors are fixed, e.g. manually created static imports. This is problematic in long files with many imports and "editor.codeActionsOnSave" : ["source.organizeImports", ...]. A typo in the "wrong" place can easily remove all your imports.
Environment
- Operating System: Ubuntu 20.04.3 LTS
- JDK version: 11.0.6+10
- Visual Studio Code version: 1.63.2
- Java extension version: 1.2.0
Steps To Reproduce
- Introduce an import
- Create a compile error that will invalidate the reference

Current Result
All "unused" imports are removed.
Expected Result
Don't remove imports when the Java file has compile errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with a Java file containing an import and a compile error, then run the Organize Imports code action or source.organizeImports on save. Trace the code-action handling to determine how compile errors affect unused-import detection; done means valid imports are retained whenever the Java file has compile errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100