[improve][build] Set --enable-native-access=ALL-UNNAMED for test JVMs on Java 24+ - #26367
Merged
Merged
Conversation
… on Java 24+
Netty loads its native libraries (epoll, io_uring, tcnative) through
java.lang.System::loadLibrary, which is a restricted method as of Java 24. Every test JVM
that touches a Netty native transport therefore prints a multi-line warning to stderr:
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by
io.netty.util.internal.NativeLibraryUtil 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
That is noise in test output, it interferes with assertions on empty stderr, and the JDK
will block restricted methods outright in a future release.
The flag is added to the Test task JVM arguments only when the Java version used to run the
tests is 24 or later, since the option is not accepted by older JVMs. The effective version
is the -PtestJavaVersion toolchain override when set, and otherwise the JVM running Gradle,
so the gate is correct for both.
This mirrors what bin/pulsar already does for the server and what the CLI scripts do for
pulsar-admin, pulsar-client, pulsar-shell and pulsar-perf.
Assisted-by: Claude Code (Opus 5)
Merged
11 tasks
nodece
approved these changes
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Netty loads its native libraries (epoll, io_uring, tcnative) through
java.lang.System::loadLibrary, which became a restricted method in Java 24. Any test JVM thattouches a Netty native transport therefore prints to stderr:
Pulsar already runs CI on JDK 25, so this is noise on every affected test JVM. It also
interferes with tests that assert a process wrote nothing to stderr, and, as the warning says,
restricted methods will eventually be blocked rather than warned about.
bin/pulsaralready passes--enable-native-access=ALL-UNNAMEDfor the server, and #26365 addsit to the CLI scripts. This PR does the same for the test JVMs.
Modifications
In
build-logic/conventions/src/main/kotlin/pulsar.java-conventions.gradle.kts:and, inside
tasks.withType<Test>().configureEach:The version gate matters because the option is not accepted by older JVMs, and tests can be run
on an older JDK via
-PtestJavaVersion. The effective version therefore honours that toolchainoverride when present and falls back to the JVM running Gradle, so the gate is correct in both
cases.
Verifying this change
This change is a trivial rework / code cleanup without any test coverage.
Verified locally that the conditional actually takes effect, in both directions, by inspecting
the test worker command line with
--rerun-tasks -i:--enable-native-access=ALL-UNNAMEDappears in the spawned test JVM arguments;
Also ran
./gradlew :buildtools:compileJavato confirm the convention plugin still compiles, anda targeted test to confirm test execution is unaffected.
Does this pull request potentially affect one of the following parts: