Skip to content

Fix Java detection fallback when Ballerina dependencies directory is missing#1557

Closed
Copilot wants to merge 2 commits intorelease/bi-1.8.xfrom
copilot/check-ballerina-home-dependencies
Closed

Fix Java detection fallback when Ballerina dependencies directory is missing#1557
Copilot wants to merge 2 commits intorelease/bi-1.8.xfrom
copilot/check-ballerina-home-dependencies

Conversation

Copy link

Copilot AI commented Feb 25, 2026

Purpose

When the dependencies folder is absent from the Ballerina home directory, Java detection fails immediately with an error rather than falling back to JAVA_HOME or platform-specific locations.

Goals

Implement a prioritized 3-step JDK lookup:

  1. ballerinaHome/dependencies — check inside the active distribution first
  2. baseHome/dependencies — check one level up (sibling to distributions/)
  3. JAVA_HOME / platform-specific system JDK — final fallback

Approach

Refactored findHighestVersionJdk() in server.ts into three composable functions:

  • findJdkInDirectory(directory) — pure directory scan, no fallback; returns null if dir missing or no matching JDK pattern
  • findSystemJdk() — checks JAVA_HOME (with WSL support) and well-known platform paths (/usr/lib/jvm, ProgramFiles\Java, etc.)
  • findHighestVersionJdk(directory) — backward-compatible wrapper: findJdkInDirectory(dir) ?? findSystemJdk()

Both getServerOptionsUsingJava (language server startup) and getJavaCommand (debugger) now use the explicit 3-step chain:

const jdkDir = findJdkInDirectory(join(ballerinaHome, 'dependencies'))
    ?? findJdkInDirectory(join(baseHome, 'dependencies'))
    ?? findSystemJdk();

Previously, findHighestVersionJdk returned null immediately when the directory didn't exist — bypassing the JAVA_HOME fallback entirely — and both callers threw an error without retrying alternative paths.

UI Component Development

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

  • Added Icons to the font-wso2-vscode. Follow the instructions.

User stories

Ballerina extension can now start the language server and debugger even when the bundled JDK (dependencies/) is absent, using JAVA_HOME as a fallback — previously a hard failure.

Release note

Fixed Java detection in the Ballerina extension: the extension now correctly falls back to JAVA_HOME when the Ballerina dependencies directory does not exist.

Documentation

N/A — internal runtime behavior change, no user-facing configuration change.

Training

N/A

Certification

N/A

Marketing

N/A

Automation tests

  • Unit tests

    No existing unit test infrastructure for this module; logic validated via scenario simulation covering: normal install, missing dependencies dir (JAVA_HOME fallback), JDK inside ballerinaHome, no JDK found (error).

  • Integration tests

    N/A

Security checks

Samples

N/A

Related PRs

N/A

Migrations (if applicable)

N/A

Test environment

Validated logic against the following scenarios on Linux:

  • Typical .ballerina/distributions/ballerina-x.y.z install with dependencies/ present
  • Missing dependencies/ folder with JAVA_HOME set
  • JDK located inside ballerinaHome/dependencies
  • No JDK found in any location

Learning

N/A

Original prompt

ballerina extension check java in ballerina home. If balleinahome/dependency folder not exist java pickup failed.

What should we need to check ballrina home /dependencis folder first

If java cannot find there then check goback one folder from java home and check dependencies folder and if java has it

If not use environment JAVA_HOME to pick jre


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

… JAVA_HOME

Co-authored-by: kanushka <24244523+kanushka@users.noreply.github.com>
Copilot AI changed the title [WIP] Check dependencies in Ballerina home for Java execution Fix Java detection fallback when Ballerina dependencies directory is missing Feb 25, 2026
Copilot AI requested a review from kanushka February 25, 2026 07:02
@kanushka kanushka marked this pull request as ready for review February 25, 2026 09:51
@kanushka kanushka closed this Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants