Skip to content

[TrimmableTypeMap] Fix [Export] JNI signature mapping for non-primitive parameter types - #11051

Merged
jonathanpeppers merged 2 commits into
mainfrom
copilot/fix-9141961-55075302-dd591e09-e008-489a-a247-c8cbff8f3695
Apr 1, 2026
Merged

[TrimmableTypeMap] Fix [Export] JNI signature mapping for non-primitive parameter types#11051
jonathanpeppers merged 2 commits into
mainfrom
copilot/fix-9141961-55075302-dd591e09-e008-489a-a247-c8cbff8f3695

Conversation

CopilotAI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Problem

The scanner's ManagedTypeToJniDescriptor() method maps managed types to JNI descriptors for [Export] method signatures. It correctly handles primitives (boolZ, intI, etc.) and stringLjava/lang/String;, but falls back to Ljava/lang/Object; for all other types. This means [Export] methods with parameters like Android.Graphics.Bitmap, Android.Views.View, or any custom Java-bound type get incorrect JNI signatures in the generated JCW, causing NoSuchMethodError at runtime.

Fix

ManagedTypeToJniDescriptor() now resolves Java-bound types by looking up their [Register] attribute via the existing TryResolveJniObjectDescriptor() infrastructure (already used by the constructor signature path), falling back to Ljava/lang/Object; only for types that truly cannot be resolved.

Changes Made

  • ManagedTypeToJniDescriptor — Added TryResolveJniObjectDescriptor call before the Ljava/lang/Object; fallback; converted from static to instance to access the assembly cache.
  • BuildJniSignatureFromManaged, ParseExportAttribute, ParseExportFieldAsMethod, TryGetMethodRegisterInfo, CollectExportField — Converted from static to instance (transitively need the assembly cache for type resolution).
  • ExportWithJavaBoundParams test type — Added with three [Export] methods taking Android.Views.View parameters.
  • Scan_ExportMethod_ResolvesJavaBoundParameterTypes test theory — Verifies correct JNI signatures for [Export] methods with non-primitive Java-bound parameter types.
  • ExportFieldTests — Updated assertion to expect the correctly resolved type name (my.app.ExportFieldExample) instead of the previous incorrect java.lang.Object fallback.

Testing

  • All 303 TrimmableTypeMap unit tests pass, including 3 new test cases.

@jonathanpeppers

Copy link
Copy Markdown
Member

@copilot can you continue what you were doing?

ManagedTypeToJniDescriptor now resolves Java-bound types via their
[Register] attribute using TryResolveJniObjectDescriptor, falling back
to Ljava/lang/Object; only for types that cannot be resolved.
Methods that call it are converted from static to instance to access
the assembly cache for type resolution.
Agent-Logs-Url: https://github.com/dotnet/android/sessions/78609547-4f51-479a-aa5a-03a5bb54a0b8
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>

CopilotAI commented Mar 30, 2026

Copy link
Copy Markdown
ContributorAuthor

@copilot can you continue what you were doing?

Done in 768a003. The fix converts ManagedTypeToJniDescriptor from static to instance and adds a TryResolveJniObjectDescriptor call before the Ljava/lang/Object; fallback — the same resolution already used by ManagedTypeToJniDescriptorOrNull for constructor signatures. Methods in the call chain (BuildJniSignatureFromManaged, ParseExportAttribute, ParseExportFieldAsMethod, TryGetMethodRegisterInfo, CollectExportField) are also converted from static to instance to access the assembly cache. All 303 tests pass, including 3 new test cases for [Export] methods with Android.Views.View parameters.

CopilotAI changed the title [WIP] Copilot Request[TrimmableTypeMap] Fix [Export] JNI signature mapping for non-primitive parameter typesMar 30, 2026
@simonrozsival
simonrozsival marked this pull request as ready for review March 31, 2026 07:28
CopilotAI review requested due to automatic review settings March 31, 2026 07:28

CopilotAI 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.

Pull request overview

Fixes incorrect JNI signature generation for [Export] (and related [ExportField]) methods when parameters/return types are non-primitive Java-bound managed types, by resolving descriptors via [Register] metadata instead of always falling back to Ljava/lang/Object;. This aligns [Export] signature computation with the existing constructor-signature resolution path.

Changes:

  • Update JavaPeerScanner.ManagedTypeToJniDescriptor() to resolve Java-bound types via TryResolveJniObjectDescriptor() before falling back to Ljava/lang/Object;.
  • Convert several helper methods from static to instance methods to access the scanner’s assembly cache for type resolution.
  • Add/adjust unit tests to validate correct JNI signatures for [Export] methods with Java-bound parameter types and for [ExportField] Java type names.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

FileDescription
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestTypes.csAdds a new fixture type with [Export] methods taking Android.Views.View parameters to exercise Java-bound parameter signature resolution.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Scanner/JavaPeerScannerTests.Behavior.csAdds a theory verifying resolved JNI signatures for the new [Export] fixture methods.
tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/ExportFieldTests.csUpdates expectation so [ExportField] return type resolves to the actual Java type instead of java.lang.Object.
src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.csImplements Java-bound type resolution in [Export] signature mapping and refactors helpers to instance methods to use the assembly cache.

@simonrozsivalsimonrozsival added copilot `copilot-cli` or other AIs were used to author this trimmable-type-map labels Mar 31, 2026
@jonathanpeppers
jonathanpeppers merged commit 1275ade into mainApr 1, 2026
9 of 10 checks passed
@jonathanpeppers
jonathanpeppers deleted the copilot/fix-9141961-55075302-dd591e09-e008-489a-a247-c8cbff8f3695 branch April 1, 2026 21:43
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 2, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

copilot`copilot-cli` or other AIs were used to author thistrimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TrimmableTypeMap] Fix [Export] JNI signature mapping for non-primitive parameter types

4 participants

@jonathanpeppers@simonrozsival