Skip to content

Conversation

@gayanW
Copy link
Contributor

@gayanW gayanW commented Jul 18, 2025

This PR addresses the following error:

% java -version
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

% launchable verify                                    

  warnings.warn(
Organization: 'defaulttm'
Workspace: 'my-initial-tests'
Proxy: None
Platform: 'macOS-15.5-arm64-arm-64bit'
Python version: '3.9.6'
Java command: 'java'
launchable version: '1.106.0'
Traceback (most recent call last):
  File "/Users/gweerakutti/Library/Python/3.9/bin/launchable", line 8, in <module>
    sys.exit(main())
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/launchable/commands/verify.py", line 137, in verify
    if check_java_version(java) < 0:
  File "/Users/gweerakutti/Library/Python/3.9/lib/python/site-packages/launchable/commands/verify.py", line 53, in check_java_version
    v = subprocess.run([javacmd, "-version"], check=True, stderr=subprocess.PIPE, universal_newlines=True)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-version']' returned non-zero exit status 1.

While /usr/bin/java might exist on users macOS system, when no JDK or JRE is installed, it typically act as a placeholder or symlink meant to guide users toward installing Java. So in such case, when we call java -version in our code, as the command returns an non-zero error code instead of the version, we need to handle it.

New behavior:

% java -version; echo "Exit code: $?"
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Exit code: 1

% launchable verify        
/Users/gweerakutti/.local/share/virtualenvs/cli-JevRS2r6/lib/python3.9/site-packages/launchable/version.py:1: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import DistributionNotFound, get_distribution
Organization: 'defaulttm'
Workspace: 'my-initial-tests'
Proxy: None
Platform: 'macOS-15.5-arm64-arm-64bit'
Python version: '3.9.6'
Java command: 'java'
launchable version: '1.106.2.dev1+ge25829f3.d20250718'
Usage: launchable verify [OPTIONS]
Try 'launchable verify --help' for help.

Error: Java 8 or later is required

While /usr/bin/java might exist on users macOS system, when no JDK or JRE is installed, it typically act as a placeholder or symlink meant to guide users toward installing Java. So in such case, when we call `java -version` it return an error instead of the version, which we need to handle.
@gayanW gayanW requested review from a team, ono-max and yoshiori and removed request for a team July 18, 2025 06:15
Updated the check_java_version function to return -1. Even if the 'java' command exists, if the 'java -version' command returns non-zero value, we can safely assume that java is not installed.
@sonarqubecloud
Copy link

Copy link
Contributor

@ono-max ono-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Thanks

@gayanW gayanW merged commit c697332 into main Jul 22, 2025
15 checks passed
@gayanW gayanW deleted the AIENG-180 branch July 22, 2025 02:34
@github-actions github-actions bot mentioned this pull request Jul 22, 2025
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