Repository navigation
[Xamarin.Android.Build.Tasks] Enable native access for javac on JDK 24+ - #13829
Conversation
On Windows CI, CodeQL's Java tracer injects its agent into every JVM, including the one started by `javac`. With JDK 24+, the agent's `SubstResolver` calls `System.load()` from an unnamed module, so JEP 472 makes the JVM print four `WARNING:` lines. `<Javac/>` reports these as `JAVAC : warning` diagnostics, which breaks tests that count warnings. `<JavaToolTask/>` already passes `--enable-native-access=ALL-UNNAMED` to `java` on JDK 24+. Pass the same option to the `javac` JVM with `-J`. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change adding a JDK-version-gated native-access option to javac.
No open issues 🎉
What changed in this PR
Updates .NET for Android’s Java compiler task to prevent JDK 24+ native-access warnings from CodeQL agents and other code running inside javac.
Changes:
- Adds
-J--enable-native-access=ALL-UNNAMEDwhen the detected JDK version is 24 or later, matching the existing Java launcher behavior. - Leaves compiler arguments unchanged for older or unrecognized JDK versions.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs | Adds the version-gated native-access option to the javac JVM command line. |
Review effort: Balanced
|
Reviewed as PeppersMuse. Checked
Copilot's review reported no open issues, and I found nothing to add. Looks good. |
|
/azp run Xamarin.Android-PR |
|
No pipelines are associated with this pull request. |
|
/azp run Xamarin.Android-PR |
|
No pipelines are associated with this pull request. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/azp run Xamarin.Android-PR |
|
No pipelines are associated with this pull request. |
|
Internal
The public CI (dnceng-public) is offline, so this internal build is the only CI result. |
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
1fda731d051a12e18cc0fbfe87ea7bffdc7ab3fe↑ A simulated agent calling
System.loadinside javac warns without the option and is silent with it.↑ The final merge changed only upstream workflows; the product diff is unchanged.
↓ Windows CodeQL tracing for the merged head remains unverified.
java/tools/tracing-config.luainjects its agent viajvmPrependArgsinto every JVM, including javac's.↑ Warnings name
SubstResolverinsemmle-extractor-java.jar, matching github/codeql#23044.JAVAC : warninglines inflating the expected warning count from 2 to 6.Context: github/codeql#23044
On Windows CI with CodeQL enabled and JDK 25,
<Javac/>reports four extra warnings, which breaks tests that count warnings (e.g.BuildHasTrimmerWarningsin build 1704054 expected 2 warnings but got 6):CodeQL's Java tracer (
java/tools/tracing-config.lua) injects-javaagent:codeql-java-agent.jarinto every JVM it traces, including the JVM started byjavac. On Windows, the extractor'sSubstResolvercallsSystem.load()from an unnamed module, and JDK 24+ prints the JEP 472 native-access warnings to stderr. The upstream fix ships in CodeQL 2.27.5, but the 1ES CodeQL3000 task currently pins 2.27.3.<JavaToolTask/>already passes--enable-native-access=ALL-UNNAMEDtojavaon JDK 24+. Pass the same option to thejavacJVM via-Jwhen$(_JdkVersion)is 24 or later. This keeps CodeQL analysis intact, and also avoids the same warnings (and future denial) for any other agent or annotation processor using native access inside javac. Older JDKs are unaffected.Validation (macOS, JDK 25.0.5.1):
make prepare CONFIGURATION=Debug MSBUILD_ARGS='-m:4' && make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:4': succeeded after merging main; one Git toolingRepository has no commitwarning.JAVA_HOME="$HOME/android-toolchain/jdk-25" ./dotnet-local.sh test --test-modules bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter 'Name~JavacTaskDoesNotRunOnSecondBuild|Name~BindingWithAndroidJavaSource': passed 4/4 after the MSTest migration.dotnet new android+Java/Foo.java, built with the local SDK and-v:detailed: javac ran asjavac -J-Dfile.encoding=UTF8 -J--enable-native-access=ALL-UNNAMED @...with no warnings.System.loadinjected into JDK 25javacwith-J-javaagent(as CodeQL does) printed the four warnings without the option and none with it.