jline / jline3

JLine is a Java library for handling console input.
Other
1.46k stars 214 forks source link

WARNING: A restricted method in java.lang.System has been called (JDK24) #1067

Closed khmarbaise closed 5 days ago

khmarbaise commented 1 week ago

Currently the jline-3.26.3 is used in Maven Core which produces a WARNING like this:

$> mvn clean verify 
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 (file:/Users/khm/tools/maven/lib/jline-3.26.3.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

This warning is issued while running under JDK24.ea.13

gnodet commented 1 week ago

@khmarbaise Which version of maven ?

khmarbaise commented 1 week ago

I have tested with Maven 4.0.0-beta-4, 4.0.0-beta-3, 3.9.X(all versions), 3.8.X(all versions)... A simple mvn --version also triggers the warning:

mvn --version
$> mvn --version
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 (file:/Users/khm/tools/maven/lib/jansi-2.4.1.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

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /Users/khm/tools/maven
Java version: 24-ea, vendor: Oracle Corporation, runtime: /Users/khm/.sdkman/candidates/java/24.ea.13-open
Default locale: en_DE, platform encoding: UTF-8
OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"

The README tells already something like this:

With JLine 3.26, the FFM provider requires JDK 22 with the --enable-native-access=ALL-UNNAMED JVM option.

If I correctly understand the warning which is related to the usage of this methods: https://download.java.net/java/early_access/jdk24/docs/api/restricted-list.html

gnodet commented 1 week ago

We need to add argument that to the startup scripts.

khmarbaise commented 1 week ago

Wouldn't it be better to go the way that jline detects which JDK it is running under automatically for example via a multi-release jar which handles that ... using FFM (JDK22+) ? (Just an idea... not familiar with the JLine code)...

gnodet commented 1 week ago

I think JLine almost always needs native access, either because of the FFM provider or because it will need to load a native library. Only the exec provider can work without native, but it's only supported on Unix systems.

slachiewicz commented 5 days ago

Also with other projects, our default validation fails.

[INFO] --- enforcer:3.5.0:enforce (enforce-bytecode-version) @ maven-filtering --- [INFO] Restricted to JDK 17 yet org.jline:jline:jar:3.26.3:test contains org/jline/terminal/impl/ffm/CLibrary$termios.class targeted to JDK 22

Error: Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.5.0:enforce (enforce-bytecode-version) on project maven-filtering: Error: Rule 0: org.codehaus.mojo.extraenforcer.dependencies.EnforceBytecodeVersion failed with message: Error: Found Banned Dependency: org.jline:jline:jar:3.26.3 Error: Use 'mvn dependency:tree' to locate the source of the banned dependencies.

gnodet commented 5 days ago

Also with other projects, our default validation fails.

[INFO] --- enforcer:3.5.0:enforce (enforce-bytecode-version) @ maven-filtering --- [INFO] Restricted to JDK 17 yet org.jline:jline:jar:3.26.3:test contains org/jline/terminal/impl/ffm/CLibrary$termios.class targeted to JDK 22

Error: Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.5.0:enforce (enforce-bytecode-version) on project maven-filtering: Error: Rule 0: org.codehaus.mojo.extraenforcer.dependencies.EnforceBytecodeVersion failed with message: Error: Found Banned Dependency: org.jline:jline:jar:3.26.3 Error: Use 'mvn dependency:tree' to locate the source of the banned dependencies.

That's unrelated and I think the detection is too strict. In this case, the JLine FFM provider requires JDK 22, but those classes are optional. Maven can be switched to using individual JLine jars if needed, that may help.

gnodet commented 5 days ago

I have tested with Maven 4.0.0-beta-4, 4.0.0-beta-3, 3.9.X(all versions), 3.8.X(all versions)... A simple mvn --version also triggers the warning:

mvn --version
$> mvn --version
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 (file:/Users/khm/tools/maven/lib/jansi-2.4.1.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

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /Users/khm/tools/maven
Java version: 24-ea, vendor: Oracle Corporation, runtime: /Users/khm/.sdkman/candidates/java/24.ea.13-open
Default locale: en_DE, platform encoding: UTF-8
OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"

The README tells already something like this:

With JLine 3.26, the FFM provider requires JDK 22 with the --enable-native-access=ALL-UNNAMED JVM option.

If I correctly understand the warning which is related to the usage of this methods: https://download.java.net/java/early_access/jdk24/docs/api/restricted-list.html

I've raised https://github.com/apache/maven/pull/1718

gnodet commented 5 days ago

Also with other projects, our default validation fails.

[INFO] --- enforcer:3.5.0:enforce (enforce-bytecode-version) @ maven-filtering --- [INFO] Restricted to JDK 17 yet org.jline:jline:jar:3.26.3:test contains org/jline/terminal/impl/ffm/CLibrary$termios.class targeted to JDK 22

Error: Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.5.0:enforce (enforce-bytecode-version) on project maven-filtering: Error: Rule 0: org.codehaus.mojo.extraenforcer.dependencies.EnforceBytecodeVersion failed with message: Error: Found Banned Dependency: org.jline:jline:jar:3.26.3 Error: Use 'mvn dependency:tree' to locate the source of the banned dependencies.

Raised https://github.com/apache/maven/pull/1719

gnodet commented 5 days ago

Closing this one as there's not much JLine can do for the JDK24 warning and for the enforcer, we need to use individual jars.