Skip to content

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

Description

@simonrozsival

Part of #10933

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:

// Scanner/JavaPeerScanner.cs:1096-1097// Fallback: any other type maps to Objectreturn"Ljava/lang/Object;";

This means [Export] methods with parameters like Android.Graphics.Bitmap, Java.Util.ArrayList, or any custom Java-bound type will get incorrect JNI signatures in the generated JCW.

Example

[Export("processImage")]publicvoidProcessImage(Android.Graphics.Bitmapbitmap){}

Expected JCW:

publicvoidprocessImage(android.graphics.Bitmapp0) { n_processImage(p0); }
privatenativevoidn_processImage(android.graphics.Bitmapp0);

Actual JCW (with fallback):

publicvoidprocessImage(java.lang.Objectp0) { n_processImage(p0); }
privatenativevoidn_processImage(java.lang.Objectp0);

Fix

The ManagedTypeToJniDescriptor() method needs to resolve Java-bound types by looking up their [Register] attribute to find the correct JNI type name. The type resolution can use the existing AssemblyIndex infrastructure to look up the target type's [Register] attribute.

Impact

Any [Export] method with non-primitive, non-string parameters will have an incorrect JNI signature. This will cause NoSuchMethodError at runtime when Java tries to call the exported method with the correct parameter types.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions