Skip to content

Replace Jansi with JLine to resolve Java 21+ native access warnings #603

@david-waltermire

Description

@david-waltermire

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:

  1. Jansi has been merged into JLine - As of JLine 3.25, Jansi was merged into the JLine project
  2. JLine 4.x removes Jansi entirely - Uses a JNI provider that handles native access more gracefully
  3. 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

  1. Custom launcher scripts - Add Java version detection to conditionally add --enable-native-access=ALL-UNNAMED
  2. Document JAVA_OPTS workaround - Users manually set the flag
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions