Skip to content

Windows native launcher should auto-add JDK 9+/25 compatibility args #426

Closed

Description

@robertpatrick

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.

Activity

  1. added this to the 2.7.5 milestone on May 30, 2026
  2. jeff5 commented on Jun 16, 2026

    @jeff5
    Member

    jython.exe is just the compiled form of ~/src/shell/jython.py, made with PyInstaller so if that meets the criteria, then so should the EXE.

  3. Stewori commented on Jun 17, 2026

    @Stewori
    Member

    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.

  4. jeff5 commented on Jun 20, 2026

    @jeff5
    Member

    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. -version is standard 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.

  5. Stewori commented on Jun 20, 2026

    @Stewori
    Member

    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?

  6. linked a pull request that will close this issueApproach Java 25 compatibility by stages #435on Jul 7, 2026
  7. Stewori commented on Jul 7, 2026

    @Stewori
    Member

    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?

  8. jeff5 commented on Jul 7, 2026

    @jeff5
    Member

    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).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions