bug icon indicating copy to clipboard operation
bug copied to clipboard

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

Open xuwei-k opened this issue 1 year ago • 6 comments

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

xuwei-k avatar Sep 03 '24 06:09 xuwei-k

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?

lrytz avatar Sep 03 '24 07:09 lrytz

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.

sjrd avatar Sep 03 '24 07:09 sjrd

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

SethTisue avatar Sep 03 '24 09:09 SethTisue

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.

lrytz avatar Sep 09 '24 10:09 lrytz

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

SethTisue avatar Nov 06 '24 18:11 SethTisue

same issue in Scala 3: https://github.com/scala/scala3/issues/22756

SethTisue avatar Mar 09 '25 22:03 SethTisue

  • https://github.com/jline/jline3/pull/1374

xuwei-k avatar Sep 28 '25 22:09 xuwei-k

Current scala-cli passes the right JVM flags to prevent this warning, so things look fine when running the REPL via scala-cli. https://github.com/VirtusLab/scala-cli/pull/3767

The warning shows up when using the scripts from the Scala 2 distribution, or when doing

java -cp $(cs fetch -p 'org.scala-lang:scala-compiler:2.13.16') scala.tools.nsc.MainGenericRunner -usejavacp

lrytz avatar Sep 29 '25 08:09 lrytz