scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

WARNING: java.lang.System::load has been called by org.jline.nativ.JLineNativeLoader in an unnamed module #13030

Open xuwei-k opened 2 months ago

xuwei-k commented 2 months ago

Reproduction steps

install jdk 24

$ java --version
openjdk 24-ea 2025-03-18
OpenJDK Runtime Environment (build 24-ea+13-1421)
OpenJDK 64-Bit Server VM (build 24-ea+13-1421, mixed mode, sharing)

launch Scala 2.13.14 REPL

Problem

$ scala
Welcome to Scala 2.13.14 (OpenJDK 64-Bit Server VM, Java 24-ea).
Type in expressions for evaluation. Or try :help.
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.jline.nativ.JLineNativeLoader in an unnamed module
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

https://openjdk.org/jeps/472

lrytz commented 2 months ago

Thanks @xuwei-k! So IIUC we're getting the warning because Scala is not using the module system (ie, using the unnamed module), as well as jline. There would be no warning if the code using JNI was in a different module

Is there any other option than adding the --enable-native-access flag?

sjrd commented 2 months ago

So IIUC we're getting the warning because Scala is not using the module system (ie, using the unnamed module)

I don't think so. AFAIU from the JEP, all code, whether in a module or not, is disallowed JNI by default. So regardless, you need a command-line option. The only difference that modules make is that you can grant specific modules access to JNI, without granting all of the code on the classpath. Whereas for code in the unnamed module, you have no choice but to grant JNI access to the entire classpath.

SethTisue commented 2 months ago

note sure whether this should also be reported to JLine 3 and perhaps to other repos such as Scala 3, scala-cli, sbt...

if we have to add --enable-native-access can that only be done at JVM start time? because if so it will need to be added by anything that might launch a Scala REPL

Yoshida-san did already open https://github.com/sbt/sbt/issues/7634 but it's about ipcsocket rather than JLine

lrytz commented 2 months ago

So IIUC we're getting the warning because Scala is not using the module system (ie, using the unnamed module)

AFAIU from the JEP, all code, whether in a module or not, is disallowed JNI by default

You're right, I got confused by this (from the JEP):

Code that merely calls a native method declared in a different module does not need to have native access enabled.

The JEP clearly says:

Library developers who rely on JNI or the FFM API should inform their users that they will need to enable native access using one of the methods below.

SethTisue commented 1 week ago

JLine ticket is https://github.com/jline/jline3/issues/1067

The discussion there seems to confirm that we need to start the JVM with --enable-native-access=ALL-UNNAMED