Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Mono.Android] Remove Mono_UnhandledException lookup
We can simplify `JNIEnv.PropagateUncaughtException` by removing the
fallback case that would attempt to look for
`System.Diagnostics.Debugger.Mono_UnhandledException`.  In .NET the
`MonodroidRuntime::monodroid_debugger_unhandled_exception` function will
always be defined, and `Mono_UnhandledException` appears to no longer
exist in .NET.  This simplification should also appease our latest set
of API scan results that were complaining about missing documentation
for `Mono_UnhandledException`.
  • Loading branch information
pjcollins committed Jan 8, 2024
commit c17b014e3b8bd9e84d1b39903104cdcde28373e8
14 changes: 0 additions & 14 deletions src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@ namespace Android.Runtime
{
public static class AndroidRuntimeInternal
{
internal static MethodInfo? mono_unhandled_exception_method = null;
internal static Action<Exception> mono_unhandled_exception = RuntimeNativeMethods.monodroid_debugger_unhandled_exception;

#pragma warning disable CS0649 // Field is never assigned to. This field is assigned from monodroid-glue.cc.
internal static volatile bool BridgeProcessing; // = false
#pragma warning restore CS0649 // Field is never assigned to.

internal static void InitializeUnhandledExceptionMethod ()
{
if (mono_unhandled_exception == null) {
mono_unhandled_exception_method = typeof (System.Diagnostics.Debugger)
.GetMethod ("Mono_UnhandledException", BindingFlags.NonPublic | BindingFlags.Static);
if (mono_unhandled_exception_method != null)
mono_unhandled_exception = (Action<Exception>) Delegate.CreateDelegate (typeof(Action<Exception>), mono_unhandled_exception_method);
}
if (mono_unhandled_exception_method == null && mono_unhandled_exception != null) {
mono_unhandled_exception_method = mono_unhandled_exception.Method;
}
}

public static void WaitForBridgeProcessing ()
{
if (!BridgeProcessing)
Expand Down
11 changes: 0 additions & 11 deletions src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,11 @@ static void ManualJavaObjectDispose (Java.Lang.Object obj)
GC.SuppressFinalize (obj);
}

static void Initialize ()
{
AndroidRuntimeInternal.InitializeUnhandledExceptionMethod ();
}

internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPtr, IntPtr javaExceptionPtr)
{
if (!JNIEnvInit.PropagateExceptions)
return;

try {
Initialize ();
} catch (Exception e) {
Android.Runtime.AndroidEnvironment.FailFast ($"Unable to initialize UncaughtExceptionHandler. Nested exception caught: {e}");
}

var javaException = JavaObject.GetObject<Java.Lang.Throwable> (env, javaExceptionPtr, JniHandleOwnership.DoNotTransfer)!;

if (Debugger.IsAttached) {
Expand Down
4 changes: 2 additions & 2 deletions src/Mono.Android/Android.Runtime/JNINativeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public static Delegate CreateDelegate (Delegate dlg)
ig.Emit (OpCodes.Leave, label);

bool filter = Debugger.IsAttached || !JNIEnvInit.PropagateExceptions;
if (filter && AndroidRuntimeInternal.mono_unhandled_exception_method != null) {
if (filter && AndroidRuntimeInternal.mono_unhandled_exception.Method != null) {
ig.BeginExceptFilterBlock ();

ig.Emit (OpCodes.Call, AndroidRuntimeInternal.mono_unhandled_exception_method);
ig.Emit (OpCodes.Call, AndroidRuntimeInternal.mono_unhandled_exception.Method);
ig.Emit (OpCodes.Ldc_I4_1);
ig.BeginCatchBlock (null!);
} else {
Expand Down