Skip to content

[Xamarin.Android.Build.Tasks] Enable native access for javac on JDK 24+ - #13829

Merged
jonathanpeppers merged 3 commits into
mainfrom
simonrozsival-codeql-tracer-warnings
Dec 1, 2026
Merged

jonathanpeppers merged 3 commits into
mainfrom
simonrozsival-codeql-tracer-warnings

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 1fda731d051a12e18cc0fbfe87ea7bffdc7ab3fe

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Post-merge local SDK build and four MSTest javac integration cases passed.
↑ A simulated agent calling System.load inside 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.
Diagnosis confidence 9/10 ↑ CodeQL 2.27.3 java/tools/tracing-config.lua injects its agent via jvmPrependArgs into every JVM, including javac's.
↑ Warnings name SubstResolver in semmle-extractor-java.jar, matching github/codeql#23044.
Evidence fit 9/10 ↑ Build 1704054 shows exactly these four JAVAC : warning lines 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. BuildHasTrimmerWarnings in build 1704054 expected 2 warnings but got 6):

JAVAC : warning : A restricted method in java.lang.System has been called
JAVAC : warning : java.lang.System::load has been called by com.semmle.util.files.SubstResolver in an unnamed module (file:/D:/a/_work/_temp/codeql3000/distribution/codeql/java/tools/semmle-extractor-java.jar)
JAVAC : warning : Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
JAVAC : warning : Restricted methods will be blocked in a future release unless native access is enabled

CodeQL's Java tracer (java/tools/tracing-config.lua) injects -javaagent:codeql-java-agent.jar into every JVM it traces, including the JVM started by javac. On Windows, the extractor's SubstResolver calls System.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-UNNAMED to java on JDK 24+. Pass the same option to the javac JVM via -J when $(_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 tooling Repository has no commit warning.
  • 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 as javac -J-Dfile.encoding=UTF8 -J--enable-native-access=ALL-UNNAMED @... with no warnings.
  • A test agent calling System.load injected into JDK 25 javac with -J-javaagent (as CodeQL does) printed the four warnings without the option and none with it.
  • Not run: the Windows CodeQL-traced test run; that needs CI.

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>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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-UNNAMED when 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

@PeppersMuse

Copy link
Copy Markdown

Reviewed as PeppersMuse. Checked src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs:

  • The version gate uses Version.TryParse (JdkVersion, ...) with Major >= 24, the same version-string format the base class already parses in JavacSupportsRelease (), so an unparseable or missing version simply leaves the flag off.
  • -J--enable-native-access=ALL-UNNAMED is passed to the javac JVM launcher, placed before the @argfile, and only affects JDK 24+, matching the CodeQL tracer diagnosis in the description (Java extraction on Windows emits native-access warnings from SubstResolver on JDK 24+ github/codeql#23044).
  • No change to the command line for older JDKs.

Copilot's review reported no open issues, and I found nothing to add. Looks good.

@jonathanpeppers

Copy link
Copy Markdown
Member

/azp run Xamarin.Android-PR

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@jonathanpeppers

Copy link
Copy Markdown
Member

/azp run Xamarin.Android-PR

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

simonrozsival and others added 2 commits November 30, 2026 19:23
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers

Copy link
Copy Markdown
Member

/azp run Xamarin.Android-PR

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@jonathanpeppers

Copy link
Copy Markdown
Member

Internal Xamarin.Android-PR build 16171124 failed. I reviewed the failures, and none of them appear to be caused by this PR. They can be ignored:

Failure Why it can be ignored
Task: PoliCheck English / Run PoliCheck Post Analysis Fails on every main build. #13838 fixes it.
Task: Windows > Build & Smoke Test / Ensure no modified/untracked files Untracked .sarif file left by the Guardian tools. Fails on every main build.
Test: R8RuntimeRemappingTests.ObfuscatedMembersRun (NativeAOT,True) Failed in the uninstall step on the emulator, not in the build.
Test: BuildAssetsTest.CheckAssetsAreIncludedInAPK File lock on the build agent (being used by another process).
Test: NuGetPackageVersionFinderTests.ShortTaskNameResolvesWithNuGetMetadataInFullMSBuild Fails on every main build.

The public CI (dnceng-public) is offline, so this internal build is the only CI result.

@jonathanpeppers
jonathanpeppers merged commit c65664e into main Dec 1, 2026
1 of 2 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-codeql-tracer-warnings branch December 1, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants