Skip to content

Commit ff777c7

Browse files
Ziad El Midaouikevinrushforth
authored andcommitted
8340004: [TestBug] Call ModuleLayer.Controller::enableNativeAccess directly rather than via reflection
Reviewed-by: angorya
1 parent 9143377 commit ff777c7

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

tests/system/src/testapp7/java/mymod/myapp7/DataUrlWithModuleLayerLauncher.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,19 +73,13 @@ public void run() {
7373
Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("mymod"));
7474
ClassLoader scl = ClassLoader.getSystemClassLoader();
7575
ModuleLayer.Controller controller = ModuleLayer.defineModulesWithOneLoader(cf, List.of(parent), scl);
76-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
77-
Method enableNativeAccessMethod = ModuleLayer.Controller.class.getMethod("enableNativeAccess", Module.class);
7876
ModuleLayer layer = controller.layer();
7977
ClassLoader moduleClassLoader = layer.findLoader("mymod");
8078
Class appClass = moduleClassLoader.loadClass("javafx.application.Application");
8179
Class webClass = moduleClassLoader.loadClass("javafx.scene.web.WebView");
82-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
83-
//controller.enableNativeAccess(webClass.getModule());
84-
enableNativeAccessMethod.invoke(controller, new Object[]{webClass.getModule()});
80+
controller.enableNativeAccess(webClass.getModule());
8581
Class testClass = moduleClassLoader.loadClass("myapp7.DataUrlWithModuleLayer");
86-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
87-
//controller.enableNativeAccess(appClass.getModule());
88-
enableNativeAccessMethod.invoke(controller, new Object[]{appClass.getModule()});
82+
controller.enableNativeAccess(appClass.getModule());
8983
Method launchMethod = appClass.getMethod("launch", Class.class, String[].class);
9084
launchMethod.invoke(null, new Object[]{testClass, args});
9185
System.exit(DataUrlWithModuleLayer.ERROR_UNEXPECTED_EXIT);

tests/system/src/testapp7/java/mymod/myapp7/LocalStorageAccessWithModuleLayerLauncher.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,18 +73,12 @@ public void run() {
7373
Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("mymod"));
7474
ClassLoader scl = ClassLoader.getSystemClassLoader();
7575
ModuleLayer.Controller controller = ModuleLayer.defineModulesWithOneLoader(cf, List.of(parent), scl);
76-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
77-
Method enableNativeAccessMethod = ModuleLayer.Controller.class.getMethod("enableNativeAccess", Module.class);
7876
ModuleLayer layer = controller.layer();
7977
ClassLoader moduleClassLoader = layer.findLoader("mymod");
8078
Class webClass = moduleClassLoader.loadClass("javafx.scene.web.WebView");
81-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
82-
//controller.enableNativeAccess(webClass.getModule());
83-
enableNativeAccessMethod.invoke(controller, new Object[]{webClass.getModule()});
79+
controller.enableNativeAccess(webClass.getModule());
8480
Class appClass = moduleClassLoader.loadClass("javafx.application.Application");
85-
// Remove reflection once JDK 22 is minimum. See JDK-8340004.
86-
//controller.enableNativeAccess(appClass.getModule());
87-
enableNativeAccessMethod.invoke(controller, new Object[]{appClass.getModule()});
81+
controller.enableNativeAccess(appClass.getModule());
8882
Class testClass = moduleClassLoader.loadClass("myapp7.LocalStorageAccessWithModuleLayer");
8983
Method launchMethod = appClass.getMethod("launch", Class.class, String[].class);
9084
launchMethod.invoke(null, new Object[]{testClass, args});

0 commit comments

Comments
 (0)