@@ -114,8 +114,8 @@ def test_java_opts(self):
114114 self .assertEqual (args [0 ], "java" )
115115 self .assertEqual (args [1 ], "-Xmx2g" )
116116 self .assertEqual (args [2 ], "-Xss2560k" )
117- self . assertEqual ( args [ 3 ], "-classpath" , args )
118- self .assertEqual (args [4 ].split (classpath_delimiter ())[- 1 ], some_jar )
117+ classpath_index = args . index ( "-classpath" )
118+ self .assertEqual (args [classpath_index + 1 ].split (classpath_delimiter ())[- 1 ], some_jar )
119119 self .assertEqual (args [- 1 ], "org.python.util.jython" )
120120 self .assertEqual (props ["foo" ], "bar" )
121121 self .assertEqual (props ["baz" ], "some property" )
@@ -133,6 +133,43 @@ def test_default_options(self):
133133 self .assertIn ("python.launcher.uname" , props )
134134 self .assertIn ("python.launcher.tty" , props )
135135
136+ def test_modern_java_options (self ):
137+ add_opens = [
138+ "--add-opens=java.base/java.io=ALL-UNNAMED" ,
139+ "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" ,
140+ ]
141+ native_access = [
142+ "--enable-native-access=ALL-UNNAMED" ,
143+ "--sun-misc-unsafe-memory-access=allow" ,
144+ ]
145+ java_version = test_support .get_java_version ()
146+
147+ env = self .get_newenv ()
148+ if is_windows :
149+ # The Windows launcher is a native executable. Unlike the script
150+ # launchers, it does not inspect the Java version and synthesize
151+ # module/native-access options, so Ant supplies those through
152+ # JAVA_OPTS when it runs launcher-based tests on newer JDKs.
153+ env ["JAVA_OPTS" ] = " " .join (add_opens + native_access )
154+ args = self .get_cmdline ([launcher , "--print" ], env )
155+ for option in add_opens + native_access :
156+ self .assertIn (option , args )
157+ return
158+
159+ args = self .get_cmdline ([launcher , "--print" ], env )
160+ if java_version >= (9 ,):
161+ for option in add_opens :
162+ self .assertIn (option , args )
163+ else :
164+ for option in add_opens :
165+ self .assertNotIn (option , args )
166+ if java_version >= (25 ,):
167+ for option in native_access :
168+ self .assertIn (option , args )
169+ else :
170+ for option in native_access :
171+ self .assertNotIn (option , args )
172+
136173 def test_mem_env (self ):
137174 env = self .get_newenv ()
138175 env ["JAVA_MEM" ] = "-Xmx4g"
@@ -249,7 +286,10 @@ def test_main():
249286 return
250287 launcher = get_launcher (sys .executable )
251288 uname = get_uname ()
252- is_windows = uname in ("cygwin" , "windows" )
289+ # On Windows, Git/MSYS/Cygwin tools may put a uname executable on PATH.
290+ # This test must still parse and assert according to the native launcher
291+ # that Jython is actually using, so trust os._name for Windows first.
292+ is_windows = os ._name == "nt" or uname in ("cygwin" , "windows" )
253293 test_support .run_unittest (
254294 TestLauncher )
255295
0 commit comments