You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[TrimmableTypeMap] Add exception handling to UCO constructor callbacks (nctor_*_uco) #11176
The UCO constructor callbacks (nctor_0_uco, nctor_1_uco, etc.) generated by TypeMapAssemblyEmitter.EmitUcoConstructor lack exception handling. If the activation constructor throws, the exception crosses the JNI boundary unhandled, causing a SIGABRT.
Current behavior
// Generated nctor_0_uco — no try/catchpublicstaticvoidnctor_0_uco(nintjnienv,nintself){if(!JniEnvironment.WithinNewObjectScope&&!JavaPeerProxy.ShouldSkipActivation(self)){varobj=(MyType)RuntimeHelpers.GetUninitializedObject(typeof(MyType));obj..ctor(refjniRef,JniObjectReferenceOptions.Copy);// If ctor throws → unhandled → SIGABRT}}
Expected behavior
Should mirror ManagedPeer.Construct which wraps the body in:
This ensures exceptions are properly reported through the JNI error mechanism instead of crashing the process.
Context
Regular UCO wrappers (n_OnCreate_uco_0, etc.) delegate to the existing n_* connector methods which already have BeginMarshalMethod/EndMarshalMethod/try-catch-finally. Only constructor UCOs are affected.
ManagedPeer.Construct (the non-trimmable equivalent) has this exception handling — see external/Java.Interop/src/Java.Interop/Java.Interop/ManagedPeer.cs:74-129.
The IL emission code is in src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs in EmitUcoConstructor.
Files to modify
src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/TypeMapAssemblyEmitter.cs — emit BeginMarshalMethod/EndMarshalMethod + try/catch/finally in EmitUcoConstructor
May need new memberrefs for BeginMarshalMethod, EndMarshalMethod, OnUserUnhandledException
Activity