Skip to content

[Trimming] Propagate GetObject constructor annotations#11437

Draft
simonrozsival wants to merge 1 commit into
mainfrom
copilot/remove-getobject-suppression
Draft

[Trimming] Propagate GetObject constructor annotations#11437
simonrozsival wants to merge 1 commit into
mainfrom
copilot/remove-getobject-suppression

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

@simonrozsival simonrozsival commented May 21, 2026

Summary

  • propagate constructor DAM annotations through Java.Lang.Object.GetObject
  • call JniValueManager.GetPeer() directly now that the Type parameter is annotated
  • remove the local UnconditionalSuppressMessage helper around GetPeer()

Part of #10794.

Validation

  • git diff --check
  • dotnet restore src/Mono.Android/Mono.Android.csproj -v:minimal
  • dotnet build src/Mono.Android/Mono.Android.csproj --no-restore -v:minimal (fails before compiling Mono.Android because this isolated worktree lacks external/Java.Interop/src/Xamarin.Android.Tools.ApiXmlAdjuster, and java-runtime later reports an environment command issue)

Annotate the GetObject generic type parameters and Type argument so constructor DAM requirements flow through to JniValueManager.GetPeer(). Remove the local UnconditionalSuppressMessage helper now that the requirement is represented at the call sites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 12:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves trimming safety in Mono.Android by propagating constructor DynamicallyAccessedMembers (DAM) annotations through the Java.Lang.Object.GetObject* APIs, allowing JniValueManager.GetPeer() to be called directly without requiring a local suppression helper.

Changes:

  • Added [DynamicallyAccessedMembers (Constructors)] annotations to the generic GetObject<T> / _GetObject<T> type parameters.
  • Annotated the internal GetObject(IntPtr, JniHandleOwnership, Type?) type parameter and removed the local UnconditionalSuppressMessage wrapper.
  • Switched to a direct call to JniEnvironment.Runtime.ValueManager.GetPeer(...).

@simonrozsival simonrozsival changed the title Propagate GetObject constructor annotations [Trimming] Propagate GetObject constructor annotations May 21, 2026
@simonrozsival simonrozsival marked this pull request as draft May 21, 2026 12:32
@simonrozsival simonrozsival marked this pull request as ready for review May 21, 2026 12:33
@jonathanpeppers
Copy link
Copy Markdown
Member

Something broke:

       (_RunILLink target) -> 
         ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/Users/runner/work/1/s/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj]

@simonrozsival simonrozsival marked this pull request as draft May 21, 2026 20:35
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