Skip to content

Commit 785e75a

Browse files
committed
Fix JVM version detection for no-dot versions
OpenJDK 25 was released very recently, and its version is simply "25" without any period symbols. The regex here was assuming at least one, and so the jvm_version() function was failing with this sort of version string. This commit generalizes the regex to work in such cases.
1 parent 477ea98 commit 785e75a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/scyjava/_jvm.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def jvm_version() -> tuple[int, ...]:
9393
if java is None:
9494
raise RuntimeError(f"No java executable found inside: {p}")
9595

96+
_logger.debug(f"Invoking `{java} -version`...")
9697
try:
9798
output = subprocess.check_output(
9899
[str(java), "-version"], stderr=subprocess.STDOUT
@@ -101,11 +102,21 @@ def jvm_version() -> tuple[int, ...]:
101102
raise RuntimeError("System call to java failed") from e
102103

103104
output = output.replace("\n", " ").replace("\r", "")
104-
m = re.match('.*version "(([0-9]+\\.)+[0-9]+)', output)
105+
m = re.match('.* version "([^"]*)"', output)
105106
if not m:
106-
raise RuntimeError(f"Inscrutable java command output:\n{output}")
107+
raise RuntimeError(
108+
"Inscrutable java command output:\n" +
109+
f"$ {java} -version\n" +
110+
output
111+
)
112+
113+
v = m.group(1)
114+
_logger.debug(f"Got Java version: {v}")
107115

108-
return tuple(map(int, m.group(1).split(".")))
116+
try:
117+
return tuple(map(int, v.split(".")))
118+
except ValueError:
119+
raise RuntimeError(f"Inscrutable java version: {v}")
109120

110121

111122
def start_jvm(options: Sequence[str] = None) -> None:

0 commit comments

Comments
 (0)