Skip to content

[Mono.Android] Suppress JDK removal warnings in FakeSSLSession peer - #13828

Merged
jonathanpeppers merged 2 commits into
mainfrom
simonrozsival-fix-fakesslsession-cert-deprecations
Dec 1, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
simonrozsival-fix-fakesslsession-cert-deprecations

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 2a4970f6be47bd6396a2b276527833f8ba531ddc

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ The generated peer contains the suppression, and javac passes with -Werror on JDK 21 and 25.
↑ 142 migrated MSTest type-map cases passed after merging main; the source diff is unchanged.
↓ Other array values and device execution were not separately validated.
Diagnosis confidence 9/10 ↑ Local javac reproduction identifies the required SSLSession method and certificate type as the sources of the three warnings.
Evidence fit 8/10 ↑ The local reproduction matches the reported three Java deprecation diagnostics.
↓ The nightly log lines were not directly re-inspected for this PR.

Every app build compiles the generated Java peer for Xamarin.Android.Net.ServerCertificateCustomValidator.TrustManager.FakeSSLSession, and <Javac/> reports:

ServerCertificateCustomValidator_TrustManager_FakeSSLSession.java:113: warning: [removal] getPeerCertificateChain() in SSLSession has been deprecated and marked for removal
ServerCertificateCustomValidator_TrustManager_FakeSSLSession.java:113: warning: [removal] X509Certificate in javax.security.cert has been deprecated and marked for removal
ServerCertificateCustomValidator_TrustManager_FakeSSLSession.java:117: warning: [removal] X509Certificate in javax.security.cert has been deprecated and marked for removal

<Javac/> puts android.jar on -classpath and uses -source 1.8 -target 1.8, so javax.net.ssl.SSLSession and javax.security.cert.X509Certificate resolve against the JDK's modules, where they are @Deprecated(forRemoval=true). The peer can't avoid them: Android's SSLSession.getPeerCertificateChain() is abstract, so the peer must implement it.

FakeSSLSession is now annotated with [Java.Lang.SuppressWarnings (Value = new [] { "removal" })], scoping the suppression to this one generated class. Emitting it required the trimmable type map's JavaAnnotationParser to serialize array-valued annotation properties ({ "a", "b" }); previously they were written with ToString().

Replacing FakeSSLSession with managed hostname matching (e.g. X509Certificate2.MatchesHostname()) would remove the Java peer entirely, but would change behavior: it would bypass the app's HttpsURLConnection.DefaultHostnameVerifier.

Validation

Before merging main:

  • make prepare CONFIGURATION=Debug && make leeroy CONFIGURATION=Debug MSBUILD_ARGS='-m:4': passed.
  • dotnet new android + dotnet build with the local SDK: passed; generated peer starts with @java.lang.SuppressWarnings (value = { "removal" }).
  • Compiled the generated peer with JDK 21 and JDK 25 using the <Javac/> arguments (-classpath android.jar:java_runtime_trimmable.jar -source 1.8 -target 1.8 -Xlint:-options): without the annotation, the 3 warnings above; with it, -Werror passes.
  • dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter "FullyQualifiedName~TrimmableTypeMap": 142 passed.

After merging main:

  • PATH="$PWD/bin/Debug/dotnet:$PATH" DOTNETSDK_WORKLOAD_MANIFEST_ROOTS="$PWD/bin/Debug/lib/sdk-manifests" DOTNETSDK_WORKLOAD_PACK_ROOTS="$PWD/bin/Debug/lib" TESTINGPLATFORM_PIPE_DIRECTORY=/tmp dotnet test --project src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter 'FullyQualifiedName~TrimmableTypeMap' --minimum-expected-tests 1 --no-ansi --no-progress -v minimal: 142 passed.

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:52

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 are reported for the warning-suppression and annotation-array serialization changes.

No open issues 🎉

What changed in this PR

This PR suppresses JDK removal warnings from the generated FakeSSLSession Java peer without changing certificate-validation behavior.

Changes:

  • Adds a class-scoped SuppressWarnings("removal") annotation to FakeSSLSession.
  • Enables the trimmable type map’s annotation parser to serialize array-valued properties as Java array initializers.
File Description
src/​Mono.Android/​Xamarin.Android.Net/​ServerCertificateCustomValidator.cs Annotates FakeSSLSession to suppress removal warnings in its generated Java peer.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​Scanner/​JavaAnnotationParser.cs Serializes annotation arrays, enabling the suppression annotation’s value.

Review effort: Balanced

@PeppersMuse

Copy link
Copy Markdown

Reviewed as PeppersMuse. Checked both files:

  • JavaAnnotationParser.cs: the new ImmutableArray<CustomAttributeTypedArgument<string>> branch matches how System.Reflection.Metadata decodes a string[] attribute argument, and the recursion renders each element through the existing String branch, producing a valid Java array initializer ({ "removal" }). The branch is placed before the String check, and the new using System.Collections.Immutable; covers it.
  • ServerCertificateCustomValidator.cs: the class-scoped [Java.Lang.SuppressWarnings (Value = new [] { "removal" })] on FakeSSLSession is what the generated Java peer needs, and this is the only array-valued annotation flowing through the parser here, so the string-only array handling covers the case.
  • The suppression is annotation-only, so no runtime behavior changes.

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.

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 16171125 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 > Tests > MSBuild 6 / Guardian: Post Analysis BinSkim scans adb.exe that a test downloads into its temp folder. Not product code.
Task: Windows > Build & Smoke Test / Ensure no modified/untracked files Untracked .sarif file left by the Guardian tools. Fails on every main build.
Test: AndroidGradleProjectTests.BindFacebook (NativeAOT) Network error in the log: UnknownHost.
Test: BindingBuildTest.AndroidMavenLibrary_KotlinValueClasses Network error in the log: nodename nor servname.
Test: BuildTest2.Plugin_Maui_Audio (NativeAOT) Network error in the log: Failed to download package.
Test: AndroidGradleProjectTests.InvalidModuleNameError (CoreCLR) Network error in the log: UnknownHost.
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

Copy link
Copy Markdown
Member

/review

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13828

@github-actions github-actions Bot 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.

⚠️ Needs Changes — CI remains red; no code findings

Reviewed both changed files in full and traced metadata decoding through Java annotation emission. 0 errors, 0 warnings, 0 suggestions. The array branch reuses the existing scalar formatting and string escaping, and the class-scoped suppression leaves hostname verification behavior unchanged.

CI: license/cla passed, but Xamarin.Android-PR [build 16171125]((devdiv.visualstudio.com/redacted) failed. The maintainer’s failure breakdown attributes the failures to existing tooling issues and network failures, and reports public CI offline. I could not independently verify the private build logs, so this is not a green-CI verdict or a finding against the patch.

Static review only; the validation reported in the PR description was not rerun.

Generated by Android PR Reviewer for #13828 · copilot · gpt61 · ~25 AIC · ⌖ ~8 AIC · ⊞ 23.1K
Comment /review to run again

@jonathanpeppers
jonathanpeppers merged commit bcfd545 into main Dec 1, 2026
1 of 2 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-fix-fakesslsession-cert-deprecations branch December 1, 2026 22:08
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