Skip to content

Organize imports removes valid imports in Java files with compile errors #2294

Open
@fvclaus

Description

@fvclaus

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
  1. Introduce an import
  2. Create a compile error that will invalidate the reference

java_compile_error_organize_import

Current Result

All "unused" imports are removed.

Expected Result

Don't remove imports when the Java file has compile errors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions