Problem
When running the CLI on Java 21+, the following warnings are displayed:
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.fusesource.jansi.internal.JansiLoader 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
This is caused by Jansi's use of native code loading via System.load(), which Java 21+ restricts as part of JEP 472: Prepare to Restrict the Use of JNI.
Current State
- Jansi version: 2.4.2 (
org.fusesource.jansi:jansi)
- The warning is cosmetic but will become a blocking error in future Java releases
- The
--enable-native-access=ALL-UNNAMED flag doesn't exist on older JREs, making it difficult to add conditionally
Proposed Solution
Migrate from Jansi to JLine:
- Jansi has been merged into JLine - As of JLine 3.25, Jansi was merged into the JLine project
- JLine 4.x removes Jansi entirely - Uses a JNI provider that handles native access more gracefully
- JLine provides the FFM provider - For JDK 22+, JLine offers a Foreign Function & Memory (FFM) provider as an alternative to JNI
Migration Path
- Replace
org.fusesource.jansi:jansi with org.jline:jline or specific JLine modules
- Update
cli-processor to use JLine's terminal/console APIs
- The
AnsiConsole and ANSI rendering functionality should have equivalent JLine APIs
References
Alternatives Considered
- Custom launcher scripts - Add Java version detection to conditionally add
--enable-native-access=ALL-UNNAMED
- Document JAVA_OPTS workaround - Users manually set the flag
- Accept the warning - Functional but not ideal for user experience
The JLine migration is preferred as it addresses the root cause and prepares for future Java releases.
Problem
When running the CLI on Java 21+, the following warnings are displayed:
This is caused by Jansi's use of native code loading via
System.load(), which Java 21+ restricts as part of JEP 472: Prepare to Restrict the Use of JNI.Current State
org.fusesource.jansi:jansi)--enable-native-access=ALL-UNNAMEDflag doesn't exist on older JREs, making it difficult to add conditionallyProposed Solution
Migrate from Jansi to JLine:
Migration Path
org.fusesource.jansi:jansiwithorg.jline:jlineor specific JLine modulescli-processorto use JLine's terminal/console APIsAnsiConsoleand ANSI rendering functionality should have equivalent JLine APIsReferences
Alternatives Considered
--enable-native-access=ALL-UNNAMEDThe JLine migration is preferred as it addresses the root cause and prepares for future Java releases.