RFR: 8339517: Add --enable-native-access flag when running tests [v2]

Kevin Rushforth kcr at openjdk.org
Wed Sep 11 22:29:09 UTC 2024


On Wed, 11 Sep 2024 22:16:23 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> When running JavaFX tests and apps with JDK 24, we now get illegal access warnings of the following form:
>> 
>> 
>> WARNING: A restricted method in java.lang.System has been called
>> WARNING: java.lang.System::load has been called by com.sun.glass.utils.NativeLibLoader in module javafx.graphics (file:build/shims/javafx.graphics/)
>> WARNING: Use --enable-native-access=javafx.graphics to avoid a warning for callers in this module
>> WARNING: Restricted methods will be blocked in a future release unless native access is enabled
>> 
>> 
>> With the current jfx master, I get 301 such warnings on my macOS system (see the `test.log` file attached to the JBS bug report).
>> 
>> In order to avoid those warnings, and to avoid the eventual errors in the future, we need to pass one of the following two options when running test programs:
>> 
>> * "java --enable-native-access=javafx.graphics,javafx.media,javafx.web" -- for unit tests in the web and systemTests subprojects, as well as in the generated `build/run.args` file
>> * "java --enable-native-access=javafx.graphics" -- for all other unit tests
>> 
>> With this patch, we are down to 5 such warnings on macOS (on Linux there are few more, but the reasons are the same). The remaining warnings are due to the following two issues:
>> 
>> 1. We are making a native JNI call from javafx.swing, which we should not be doing. This is a JavaFX bug. The native library in question is loaded by the javafx.graphics modules, so the solution will likely be to move the native method call to somewhere in javafx.graphics and call that new method from javafx.swing.
>> 2. We have two unit tests that use a custom `ModuleLayer` to load the JavaFX modules at runtime, after the test application is launched. In this case the "--enable-native-access" is ineffective. I suspect this is a JDK bug.
>> 
>> I will file a pair of follow-on bugs for these.
>
> Kevin Rushforth has updated the pull request incrementally with one additional commit since the last revision:
> 
>   ModuleLayer tests need to enable native access for unnamed module

Update on problem 2:

> We have two unit tests that use a custom `ModuleLayer` to load the JavaFX modules at runtime, after the test application is launched. In this case the "--enable-native-access" is ineffective. I suspect this is a JDK bug.

This turned out to be a test bug. When using a custom `ModuleLayer` to load classes, a test (or application) needs to call `ModuleLayer.Controller::enableNativeAccess`. So the follow-up bug will be to do this in those tests.

(the reason it will be a follow-up bug is that `ModuleLayer.Controller::enableNativeAccess` was preview in JDK 21 and final in JDK 22 along with Panama, so unless we want to do this via reflection, we need to wait until we bump the minimum JDK for JavaFX).

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1562#issuecomment-2344812737


More information about the openjfx-dev mailing list