JDK 25 restricted method warning
As you're probably well aware, JDK 25 now emits the following warning:
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by com.github.luben.zstd.util.Native$2 in an unnamed module (file:/Users/xxx/.m2/repository/com/github/luben/zstd-jni/1.5.7-4/zstd-jni-1.5.7-4.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
The "Use --enable-native-access=ALL-UNNAMED" advice is clear enough, but I wanted to raise the question of what this means for future JDK releases with respect to this library.
Does this imply that JNI needs to be migrated to Java Foreign Function and Memory (FFM)? Or is it just saying that a future JDK release will start to enforce the need to specify native components irrespective of JNI or FFM?
I tried --enable-native-access=com.github.luben.zstd but that failed, as the warning already stated the module is unnamed!
Would it be possible to give this module a name so we can name it specifically for native access?
Interesting. Yes, looks like this warning will also affect FFM. From https://openjdk.org/jeps/472 :
The --enable-native-access=ALL-UNNAMED option is coarse-grained: It lifts native access restrictions on JNI and the FFM API for all classes on the class path.
We already generate the module (since v1.5.5-7), it's equivalent to:
module com.github.luben.zstd_jni {
// version: 1.5.7-6
requires java.base;
exports com.github.luben.zstd;
exports com.github.luben.zstd.util;
}
Probably using it as a module also requires to put the jar on the module path, not on the class path. Please chime back If you find a solution that is more limited than --enable-native-access=ALL-UNNAMED