Skip to content

Commit 22e048f

Browse files
authored
Merge pull request #1269 from Thrameos/min_version
Min version
2 parents 1ae3814 + f0a36c1 commit 22e048f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

doc/CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ Latest Changes:
2929

3030
- Fixed a bug in which JPype did not respect a JConversion between two Java classes.
3131

32+
- Support for minimum_version argument on startJVM.
33+
3234
- Enhancement in convertToDirectBuffer to support wrapping bytes and readonly
3335
memoryviews as readonly java ByteBuffers.
3436

37+
3538
- **1.5.2 - 2025-01-20**
3639

3740
- Roll back agent change due to misbehaving JVM installs.

jpype/_core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def startJVM(
203203
ignoreUnrecognized: bool = False,
204204
convertStrings: bool = False,
205205
interrupt: bool = not interactive(),
206+
minimum_version: typing.Optional[str] = None,
206207
) -> None:
207208
"""
208209
Starts a Java Virtual Machine. Without options it will start
@@ -366,7 +367,17 @@ def startJVM(
366367
locale.setlocale(i, j)
367368
except locale.Error:
368369
pass
369-
except RuntimeError as ex: # pragma: no cover, # todo: this assumed it was manually tested.
370+
371+
if minimum_version is not None:
372+
version = _jpype.JClass("java.lang.System").getProperty("java.version")
373+
from packaging.version import parse
374+
v1 = parse(minimum_version)
375+
v2 = parse(str(version))
376+
if v1 > v2:
377+
err = "Version of JVM is less than minimum requested. (%s<%s, path=%s)" % (v2, v1, jvmpath)
378+
raise RuntimeError(err)
379+
380+
except RuntimeError as ex:
370381
source = str(ex)
371382
if "UnsupportedClassVersion" in source:
372383
import re

0 commit comments

Comments
 (0)