clikt icon indicating copy to clipboard operation
clikt copied to clipboard

Warning "A restricted method in java.lang.System has been called" is printed with Java24

Open paul-dingemans opened this issue 5 months ago • 2 comments

Tnx for providing clikt. Clikt is used in ktlint. During some tests I noticed that the "--help" command on Java 24 results in printing the warning below:

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by com.sun.jna.Native in an unnamed module (file:/Users/xxx/clikt/samples/repo/build/install/repo/lib/jna-5.14.0.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 problem can be reproduced with the sample repo of clikt. With Java 21 the output of ./runsample repo is:

Usage: repo [<options>] <command> [<args>]...

  Repo is a command line tool that showcases how to build complex command line interfaces with Clikt.

  This tool is supposed to look like a distributed version control system to show how something like this can be structured.

Options:
  --version           Show the version and exit
  --repo-home=<text>  Changes the repository folder location.
  --config=<text>...  Overrides a config key/value pair.
  -v, --verbose       Enables verbose mode.
  -h, --help          Show this message and exit

Commands:
  clone    Clones a repository.
  delete   Deletes a repository.
  setuser  Sets the user credentials.
  commit   Commits outstanding changes.

With Java 24 the output of ./runsample repo is:

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader in an unnamed module (file:/Users/pdingemans/.gradle/wrapper/dists/gradle-8.10-bin/deqhafrv1ntovfmgh0nh3npr9/gradle-8.10/lib/native-platform-0.22-milestone-26.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

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by com.sun.jna.Native in an unnamed module (file:/xxx/clikt/samples/repo/build/install/repo/lib/jna-5.14.0.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

Usage: repo [<options>] <command> [<args>]...

The first block of warning is produced while building. The second block while executing --help.

paul-dingemans avatar Jul 06 '25 10:07 paul-dingemans

This is https://openjdk.org/jeps/472. The first one is from Gradle, they'll probably suppress at some point, likely in version 9. The second one is from Clikt and will occur whether you're using JNA or FFM. You will have to add the suppression from the message to your start script to suppress.

JakeWharton avatar Jul 06 '25 14:07 JakeWharton

This is mentioned in the mordant docs, but it's hard to find, and with Java 24 becoming more widespread, it's worth making that info more prominent.

ajalt avatar Jul 07 '25 15:07 ajalt