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
[Mono.Android] Partially constructed Throwable leaks GREF when SetJavaStackTrace fails #13066
When constructing a Java.Lang.Throwable wrapper or activating one through the typemap with DoNotRegister, if SetJavaStackTrace throws an exception (such as IllegalStateException or other runtime exceptions during printStackTrace), the partially constructed peer instance is aborted without calling Dispose().
This causes the global reference allocated by Construct to leak permanently, and in cases where DoNotRegister is not set, leaves the partially constructed wrapper registered in ValueManager.
This issue causes Java.InteropTests.TransferredReferenceTests.RuntimeExceptionLookupFailureReleasesInput(4, ...) to fail on macOS emulator test runs:
The partially constructed wrapper's own copies must be disposed separately. Expected: <empty> But was: < [29354, " at Java.InteropTests.TransferredReferenceTests.ReferenceObserver.CreateGlobalReference(JniObjectReference reference) at Java.Interop.JniObjectReference.NewGlobalRef() at Microsoft.Android.Runtime.TrimmableTypeMapValueManager.ConstructPeerCore(IJavaPeerable peer, JniObjectReference& reference, JniObjectReferenceOptions options) at Java.Interop.JniRuntime.JniValueManager.ConstructPeer(IJavaPeerable peer, JniObjectReference& reference, JniObjectReferenceOptions options) at Java.Interop.JavaException.Construct(JniObjectReference& reference, JniObjectReferenceOptions options) at Java.Lang.Throwable.SetHandle(IntPtr value, JniHandleOwnership transfer)
Steps to Reproduce
Run RuntimeExceptionLookupFailureReleasesInput(4, DoNotTransfer) or TransferLocalRef / TransferGlobalRef on the emulator test suite.
Expected Behavior
If SetJavaStackTrace throws inside Throwable.SetHandle, the wrapper should be disposed before re-throwing so allocated GREFs are released and uncompleted peers are removed from the runtime value manager.
Actual Behavior
SetJavaStackTrace is not wrapped in a try/catch in Throwable.SetHandle, so an exception during stack trace capture leaks the allocated GREF and fails stage 4 reference assertions.
Activity
[Mono.Android] Dispose partially constructed Throwable if SetJavaStac…
[Mono.Android] Dispose Throwable when stack trace extraction fails
[Mono.Android] Dispose Throwable when stack trace initialization fails
[Java.Interop] Simplify single-style JCW generation (#13060)
[r8] Retain field names for safe inherited JNI lookup (dotnet#13062)