Skip to content

Commit 0788e10

Browse files
committed
Check if the JVM is running before checking version
This commit fixes a bug where we fail to reach the cjdk fetch code if no JVM is installed first. Specifically, when `_prepare_to_unlock_modules()` is called it first tries to collect the major version calling `_guess_java_version()`. Once here, we hit the try/except and then return on the exception, instead of hitting the JDK fetch code. All we needed to do was check if there is a running JVM first. If there is not, we bypass the try/except and hit cjdk. Closes #337
1 parent 8c408a1 commit 0788e10

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/imagej/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,15 +1708,16 @@ def _create_jvm(
17081708
def _guess_java_version() -> Optional[int]:
17091709
# Ask scyjava what version of Java will be used.
17101710
version_digits = None
1711-
try:
1712-
version_digits = sj.jvm_version()
1713-
_logger.debug(f"Detected existing Java version: {version_digits}")
1714-
major_version = version_digits[0]
1715-
except JVMNotFoundException as e:
1716-
# This is OK -- it just means no already installed Java is known.
1717-
# But scyjava might download and cache a JDK, so we'll proceed with
1718-
# that understanding.
1719-
_logger.debug(e)
1711+
if sj.jvm_started():
1712+
try:
1713+
version_digits = sj.jvm_version()
1714+
_logger.debug(f"Detected existing Java version: {version_digits}")
1715+
major_version = version_digits[0]
1716+
except JVMNotFoundException as e:
1717+
# This is OK -- it just means no already installed Java is known.
1718+
# But scyjava might download and cache a JDK, so we'll proceed with
1719+
# that understanding.
1720+
_logger.debug(e)
17201721

17211722
# In scyjava 1.12.0+, if a JDK fetch is planned, the jvm_version()
17221723
# result will be invalid because that function is reporting on an

0 commit comments

Comments
 (0)