Skip to content

JDK_HOME can be sorted after lower-priority auto-detected JDK sources #4426

@shblue21

Description

@shblue21

Describe the bug
When java.jdt.ls.java.home and java.home are unset, a JDK from JDK_HOME can be sorted after JDKs detected from JAVA_HOME, PATH, or other sources.

JDK_HOME should be the top-priority environment variable in this case.

To Reproduce

  1. Leave java.jdt.ls.java.home, java.home, and java.configuration.runtimes unset.
  2. Ensure java.configuration.detectJdksAtStart is enabled.
  3. Set JDK_HOME to a valid JDK.
  4. Make a different valid JDK available through JAVA_HOME or PATH.
  5. Restart VS Code.
  6. Open Java: Configure Java Runtime and check the detected JDK order.

Actual behavior
The JDK_HOME JDK can appear after lower-priority detected JDKs.

Expected behavior
The JDK_HOME JDK appears first.

Environment

  • Operating System: macOS
  • JDK version: JDK 17 from JDK_HOME, JDK 25 from JAVA_HOME
  • Visual Studio Code version: 1.125.0-insider
  • Java extension version: 1.55.0

Additional Information
sortJdksBySource() assigns JDK_HOME rank 0, but the later if (jdk.rank) check skips it because 0 is falsy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions