Skip to content

[Mono.Android] Fix handwritten XML doc warnings and narrow NoWarn - #13871

Open
simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-mono-android-xmldoc-fixes
Open

simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-mono-android-xmldoc-fixes

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 11ed658137c375ecf963418283ab0f00432b2d1a

Dimension Assessment Rationale
Change confidence 9.5/10 ↑ All 8 handwritten XML-doc warnings and the JavadocInfo NRE are fixed and verified across API 37 and API 37.2 IncludeAndroidJavadoc=True builds, Release GenerateDocumentationFile=true, CheckApiCompatibility, and 524/524 generator unit tests.
↓ CI and API 37.1 Javadoc builds have not yet run.
Diagnosis confidence 9.5/10 ↑ Unmasked IncludeAndroidJavadoc=True builds directly reproduced the JavadocInfo.GetExtra NullReferenceException (missing <copyright> element after aab67910e6) and all 8 handwritten compiler diagnostics.
Evidence fit 9.5/10 ↑ Generated Mono.Android.xml verifies resolved cref targets and confirms CS1574, CS1584, and CS1658 drop to zero occurrences across API 37 and API 37.2.

Context: #12220 (aab67910e6), #5651

When $(IncludeAndroidJavadoc) is True, src/Mono.Android/Mono.Android.csproj suppresses CS1572;CS1573;CS1574;CS1584;CS1587;CS1591;CS1658 to accommodate imported Android Javadoc comments. That blanket suppression masked eight real XML documentation bugs in handwritten Mono.Android sources, and three of those warning codes (CS1574, CS1584, CS1658) are no longer emitted by generated bindings at all.

Additionally, building Mono.Android.csproj with -p:IncludeAndroidJavadoc=True failed in the _GenerateBinding target with:

error BG0000: System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoDroid.Generation.JavadocInfo.GetExtra(...) in src/generator/Java.Interop.Tools.Generator.ObjectModel/JavadocInfo.cs:line 131

Guard missing <copyright> in JavadocInfo.GetExtra

Commit aab67910e6 stopped passing --doc-copyright to java-source-utils, so android-javadoc.xml no longer contains a <javadoc-metadata>/<copyright> element. JavadocInfo.GetExtra still unconditionally dereferenced javadocMetadata.Element ("copyright").Elements ().

Guard the <copyright> lookup and only append copyright elements when present, matching BoundProperty.AddJavadocs, which already handles a null Copyright.

Handwritten XML documentation fixes and narrowed $(NoWarn)

Unmasking XML documentation warnings under -p:IncludeAndroidJavadoc=True surfaced eight non-CS1591 warnings in handwritten src/Mono.Android/ sources:

  • ValueTypeFactory.cs (CS1573 x2): document the handle and transfer parameters on CreateReferenceMixedDictionary.
  • ITypeMap.cs (CS1574): qualify Java.Interop.JavaPeerProxy in <see cref> so it resolves from Microsoft.Android.Runtime.
  • AndroidMessageHandler.cs (CS1574 x2): update <see cref> targets to AndroidHttpResponseMessage.Dispose(bool) and TrustedCerts (fixing a TrustCerts typo).
  • JniMarshalTyped.tt and generated JniMarshalTyped.cs (CS1584, CS1658): replace unsupported function-pointer parameter syntax in <see cref> with JniMarshal.SafeInvokeAction.
  • TrimmableTypeMapTypeManager.cs (CS1587): convert the XML doc comment on local function TryGetBuiltInReferenceJniName to a regular comment.

With those fixed, generated binding Javadoc across API 37 and API 37.2 emits zero CS1574, CS1584, or CS1658 warnings (while still emitting CS1572, CS1573, CS1587, and CS1591, plus one unsuppressed CS1571 in Android.Webkit.PluginData from AOSP's duplicate @param length). Remove CS1574, CS1584, and CS1658 from $(NoWarn) in the $(IncludeAndroidJavadoc) == 'True' property group of Mono.Android.csproj so future handwritten cref and syntax errors are caught.

Validation

  • bin/Debug/dotnet/dotnet build src/Mono.Android/Mono.Android.csproj -c Debug -p:IncludeAndroidJavadoc=True --no-dependencies -p:TreatWarningsAsErrors=false -p:WarningsAsErrors= (API 37): passed; 0 handwritten warnings, only 1 generated CS1571 (Android.Webkit.PluginData.cs), CheckApiCompatibility reported 0 issues.
  • bin/Debug/dotnet/dotnet build src/Mono.Android/Mono.Android.csproj -c Debug --no-dependencies -p:AndroidApiLevel=37.2 -p:AndroidPlatformId=37.2 -p:AndroidFrameworkVersion=v17.2 -p:IsUnstableVersion=false -p:IncludeAndroidJavadoc=True -p:_AndroidJavadocXml=../../bin/BuildDebug/android-javadoc-37.2.xml -p:TreatWarningsAsErrors=false -p:WarningsAsErrors=: passed; 0 handwritten warnings, only 1 generated CS1571.
  • bin/Debug/dotnet/dotnet build src/Mono.Android/Mono.Android.csproj -c Debug --no-dependencies: passed with 0 warnings and 0 errors.
  • bin/Debug/dotnet/dotnet build src/Mono.Android/Mono.Android.csproj -c Release -p:DotNetPreviewTool="$PWD/bin/Debug/dotnet/dotnet" -p:GenerateDocumentationFile=true -p:NoWarn=CS1591: passed with 0 Mono.Android warnings (TreatWarningsAsErrors=true) and 0 CheckApiCompatibility issues.
  • bin/Debug/dotnet/dotnet build src/Mono.Android/Mono.Android.csproj -c Release --no-dependencies -p:DotNetPreviewTool="$PWD/bin/Debug/dotnet/dotnet": passed with 0 warnings and 0 errors.
  • bin/Debug/dotnet/dotnet test tests/generator-Tests/generator-Tests.csproj -c Debug: 506/506 passed.
  • bin/Debug/dotnet/dotnet test tests/Java.Interop.Tools.Generator-Tests/Java.Interop.Tools.Generator-Tests.csproj -c Debug: 18/18 passed.

simonrozsival and others added 2 commits December 1, 2026 23:59
Commit aab6791 stopped passing `--doc-copyright` to
`java-source-utils` when generating `android-javadoc.xml`, so
`<javadoc-metadata>` no longer contains a `<copyright>` child element.
`JavadocInfo.GetExtra` unconditionally dereferenced
`javadocMetadata.Element ("copyright").Elements ()`, causing
`NullReferenceException` whenever `Mono.Android.csproj` was built with
`-p:IncludeAndroidJavadoc=True`.

Guard the `<copyright>` lookup and only append copyright elements when
present (matching `BoundProperty.AddJavadocs`, which already handles a
null `Copyright`).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fix all handwritten XML documentation comment warnings in
`src/Mono.Android/` that were masked under `IncludeAndroidJavadoc=True`:

- `ValueTypeFactory.cs`: document missing `handle` and `transfer`
  parameters on `CreateReferenceMixedDictionary` (`CS1573`).
- `ITypeMap.cs`: qualify `Java.Interop.JavaPeerProxy` in `<see cref>`
  (`CS1574`).
- `AndroidMessageHandler.cs`: fix `<see cref>` targets to
  `AndroidHttpResponseMessage.Dispose(bool)` and `TrustedCerts`
  (`CS1574`).
- `JniMarshalTyped.tt` / `JniMarshalTyped.cs`: replace unsupported
  function-pointer parameter syntax in `<see cref>` with
  `JniMarshal.SafeInvokeAction` (`CS1584`, `CS1658`).
- `TrimmableTypeMapTypeManager.cs`: replace XML doc comment on local
  function `TryGetBuiltInReferenceJniName` with a regular comment
  (`CS1587`).

Remove `CS1574`, `CS1584`, and `CS1658` from the
`IncludeAndroidJavadoc=True` `<NoWarn>` in `Mono.Android.csproj`, as
zero generated binding Javadoc comments emit them across API 37 and
API 37.2.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 23:14

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 documentation fixes and optional copyright metadata handling.

No open issues 🎉

What changed in this PR

Fixes Mono.Android XML documentation warnings and a generator crash caused by optional copyright metadata after documentation notices were moved.

Changes:

  • Corrects handwritten XML documentation and keeps the marshal template and generated source aligned.
  • Removes suppression of CS1574, CS1584, and CS1658.
  • Handles missing copyright metadata without losing documentation links.
File Description
src/​Mono.Android/​Xamarin.Android.Net/​AndroidMessageHandler.cs Corrects two documentation references.
src/​Mono.Android/​Mono.Android.csproj Narrows Javadoc warning suppression.
src/​Mono.Android/​Microsoft.Android.Runtime/​TrimmableTypeMapTypeManager.cs Converts local-function documentation to a regular comment.
src/​Mono.Android/​Microsoft.Android.Runtime/​ITypeMap.cs Qualifies the proxy attribute documentation reference.
src/​Mono.Android/​Java.Interop/​ValueTypeFactory.cs Documents two missing parameters.
src/​Mono.Android/​Java.Interop/​JniMarshalTyped.tt Fixes the template’s method reference syntax.
src/​Mono.Android/​Java.Interop/​JniMarshalTyped.cs Mirrors the template documentation fix.
src/​generator/​Java.Interop.Tools.Generator.ObjectModel/​JavadocInfo.cs Guards absent copyright metadata.

Review effort: Balanced

@PeppersMuse

Copy link
Copy Markdown

Reviewed the diff and checked each fix against the sources it touches:

  • JniMarshalTyped.cs / .tt: the bare <see cref="JniMarshal.SafeInvokeAction" /> is unambiguous — it binds to the single non-generic overload in src/Java.Interop/Java.Interop/JniMarshal.SafeInvoke.cs (line 21); all the other overloads are generic (SafeInvokeAction<T0>, etc.) and need arity notation to be referenced, so no CS0419. The old function-pointer-signature cref was indeed unsupportable (CS1584/CS1658). Template and generated file stay in sync.
  • ValueTypeFactory.cs: the two new <param> docs match the actual signature of CreateReferenceMixedDictionary — IntPtr handle, JniHandleOwnership transfer.
  • ITypeMap.cs: JavaPeerProxy lives in Java.Interop (src/Mono.Android/Java.Interop/JavaPeerProxy.cs), so the fully-qualified cref from Microsoft.Android.Runtime is the right fix for the CS1574.
  • AndroidMessageHandler.cs: AndroidHttpResponseMessage.Dispose(bool) exists (Dispose (bool disposing)), and TrustedCerts is the real property name (line 816) — TrustCerts was a genuine typo.
  • TrimmableTypeMapTypeManager.cs: converting the /// comment on local function TryGetBuiltInReferenceJniName to // is the correct CS1587 fix — XML doc comments aren't valid on local functions.
  • Mono.Android.csproj: narrowing NoWarn by dropping CS1574, CS1584, and CS1658 lines up with the fixes above; the codes that generated bindings still emit (CS1572, CS1573, CS1587, CS1591) stay suppressed.
  • JavadocInfo.cs: the ?.Elements() guard plus the copyright != null check fixes the NRE when <copyright> is absent, and the return already uses copyright?.ToArray(). Matches the existing null-tolerant handling in BoundProperty.AddJavadocs.

Copilot also reviewed this one and recommended approval with no open issues; my checks above agree. Nothing further to flag.

This branch has not been deployed

No deployments
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.

3 participants