You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows native launcher should auto-add JDK 9+/25 compatibility args #426
The Unix/Python launchers detect the Java major version and add required JDK compatibility options automatically. The Windows native launcher does not do this today; it only forwards options supplied through the JAVA_OPTS environment variable.
That means Jython native Windows launcher can be made to work in build/test automation by setting JAVA_OPTS, but users running jython.exe directly on newer JDKs need to know the required flags themselves. Jython should automatically detect the Java version and add the appropriate compatibility flags if they have not already been provided by the user.
JDK 8:
no extra compatibility arguments
JDK 9 through JDK 24:
--add-opens=java.base/java.io=ALL-UNNAMED
JDK 25 and newer:
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
--enable-native-access=ALL-UNNAMED
--sun-misc-unsafe-memory-access=allow
Acceptance criteria:
jython.exe detects the Java major version.
It adds the same compatibility arguments as the script launchers.
It does not duplicate an option already supplied through JAVA_OPTS or launcher JVM args native for users.
I can volunteer to make the PR for this issue according to Robert's specs. Should be straight forward with AI assistance.
However, we should agree on how to detect Java version. Obvious way is to parse output of java -version with java being the full command detected and used by the launcher anyway. However, AFAIK, the output format is not reliably standardized accross Java versions and vendors. So, a better option might be to grab the java.version (or maybe java.specification.version) line from the output of java -XshowSettings:properties. This option is said to be well supported accross versions and vendors.
Third way is to run a small Java file version.class which gets it programatically. Pro: we control the output format; con: yet another file to deploy. Yet another way is to find java_home and read hava_home/release. That is the only way that would not require a preparational java execution. The file, however, is only present from Java 9 onwards, but that should suffice. OTOH, if the file is missing, it might be too harsh to plainly fail. We should make a java call as fallback then.
Another question to specify is how -print should behave. I think the usual promise of print is to show the command without actually calling Java. Now the print output would become dependent on the detection result, which may require jvm execution. The easiest solution is to adjust the promise such that the detection is allowed. More advanced would be to add some other option to control the behavior, e.g. to force pre-detection print (i.e. without the additional options), post-detection print or print the command used for detection.
Do we need an option to suppress the detection? And just perform the old behavior passing the responsibility to the user (they can pass the required args through the Jython command).
This is all fairly easy in the python-based launcher. But we also need it for the bash one I suppose.
Obviously there's an attempt (taken from Robert's work) in #435, but room for improvement subsequently. Or that PR can be abandoned (maybe reset) and an independent response made to this issue first. In that case, though, it would be essential to have it in master before #435 (or successor) is deemed ready. A correct launcher, compiled for Windows, obviates some of the content of #424, but I can't figure out what without the actual launcher.
I think I must complete (not necessarily merge) #435 anyway as an investigation of that point. If the only problem is the reliability of java -version, the outcome will be the same as it that works where I've tried it. -versionisstandard across all JVMs AFAICT, but it is true the form of the output is not specified. Anything beginning -X isn't standard, and I can't tell if $JAVA_HOME/release is.
Fair point about -X. java_home/release is specified as part of JEP 220, if that counts as standard (IIRC, Jython requires Java 9+ anyway). File-reading is way more lightweight than spawning a Java process to read version. Maybe, try reading the file and fallback to java -version?
It occurs to me, is there a reason why the Linux launcher jython.sh (actually just jython) would not need the same adjustments? Are they Windows-specific?
jython shell script and jython.py both got the changes that add the options according to Java version. The missing understanding was that jython.exe is generated from jython.py and continues to be unsatisfactory until that is done.
As a result, the logic to add the options has been duplicated in various places to ensure tests run correctly on Windows with the (unregenerate) launcher. But if I regenerate the .exe and drop the extra logic out, it works. (See #435 (comment).)
Activity
jeff5 commentedon Jun 16, 2026
jython.exeis just the compiled form of~/src/shell/jython.py, made withPyInstallerso if that meets the criteria, then so should the EXE.Stewori commentedon Jun 17, 2026
I can volunteer to make the PR for this issue according to Robert's specs. Should be straight forward with AI assistance.
However, we should agree on how to detect Java version. Obvious way is to parse output of
java -versionwithjavabeing the full command detected and used by the launcher anyway. However, AFAIK, the output format is not reliably standardized accross Java versions and vendors. So, a better option might be to grab thejava.version(or maybejava.specification.version) line from the output ofjava -XshowSettings:properties. This option is said to be well supported accross versions and vendors.Third way is to run a small Java file
version.classwhich gets it programatically. Pro: we control the output format; con: yet another file to deploy. Yet another way is to find java_home and readhava_home/release. That is the only way that would not require a preparational java execution. The file, however, is only present from Java 9 onwards, but that should suffice. OTOH, if the file is missing, it might be too harsh to plainly fail. We should make a java call as fallback then.Another question to specify is how
-printshould behave. I think the usual promise of print is to show the command without actually calling Java. Now the print output would become dependent on the detection result, which may require jvm execution. The easiest solution is to adjust the promise such that the detection is allowed. More advanced would be to add some other option to control the behavior, e.g. to force pre-detection print (i.e. without the additional options), post-detection print or print the command used for detection.Do we need an option to suppress the detection? And just perform the old behavior passing the responsibility to the user (they can pass the required args through the Jython command).
This is all fairly easy in the python-based launcher. But we also need it for the bash one I suppose.
jeff5 commentedon Jun 20, 2026
Obviously there's an attempt (taken from Robert's work) in #435, but room for improvement subsequently. Or that PR can be abandoned (maybe reset) and an independent response made to this issue first. In that case, though, it would be essential to have it in
masterbefore #435 (or successor) is deemed ready. A correct launcher, compiled for Windows, obviates some of the content of #424, but I can't figure out what without the actual launcher.I think I must complete (not necessarily merge) #435 anyway as an investigation of that point. If the only problem is the reliability of
java -version, the outcome will be the same as it that works where I've tried it.-versionis standard across all JVMs AFAICT, but it is true the form of the output is not specified. Anything beginning-Xisn't standard, and I can't tell if$JAVA_HOME/releaseis.Stewori commentedon Jun 20, 2026
Fair point about
-X.java_home/releaseis specified as part of JEP 220, if that counts as standard (IIRC, Jython requires Java 9+ anyway). File-reading is way more lightweight than spawning a Java process to read version. Maybe, try reading the file and fallback tojava -version?Stewori commentedon Jul 7, 2026
It occurs to me, is there a reason why the Linux launcher
jython.sh(actually justjython) would not need the same adjustments? Are they Windows-specific?jeff5 commentedon Jul 7, 2026
jythonshell script andjython.pyboth got the changes that add the options according to Java version. The missing understanding was thatjython.exeis generated fromjython.pyand continues to be unsatisfactory until that is done.As a result, the logic to add the options has been duplicated in various places to ensure tests run correctly on Windows with the (unregenerate) launcher. But if I regenerate the .exe and drop the extra logic out, it works. (See #435 (comment).)