Skip to content

Commit 4da4e84

Browse files
[Mono.Android] fix AndroidRuntime.UnboxException()
`Java.InteropTests.JavaExceptionTests.InnerExceptionIsNotAProxy()` fails with: Expected: same as <System.InvalidOperationException: Managed Exception!> But was: <Java.Interop.JavaProxyThrowable: System.InvalidOperationException: Managed Exception! This fails to build with: src\Mono.Android\Android.Runtime\AndroidRuntime.cs(78,60): error CS0122: 'JniRuntime.JniValueManager.TryUnboxPeerObject(IJavaPeerable, out object?)' is inaccessible due to its protection level
1 parent e2f0960 commit 4da4e84

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Mono.Android/Android.Runtime/AndroidRuntime.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public override string GetCurrentManagedThreadStackTrace (int skipFrames, bool f
7575

7676
Exception? UnboxException (IJavaPeerable value)
7777
{
78-
if (JNIEnvInit.ValueManager is AndroidValueManager vm) {
79-
return vm.UnboxException (value);
78+
if (JNIEnvInit.ValueManager is JniValueManager vm && vm.TryUnboxPeerObject (value, out var r) && r is Exception e) {
79+
return e;
8080
}
8181
return null;
8282
}
@@ -865,15 +865,6 @@ protected override bool TryUnboxPeerObject (IJavaPeerable value, [NotNullWhen (t
865865
return base.TryUnboxPeerObject (value, out result);
866866
}
867867

868-
internal Exception? UnboxException (IJavaPeerable value)
869-
{
870-
object? r;
871-
if (TryUnboxPeerObject (value, out r) && r is Exception e) {
872-
return e;
873-
}
874-
return null;
875-
}
876-
877868
public override void CollectPeers ()
878869
{
879870
GC.Collect ();

src/Mono.Android/Microsoft.Android.Runtime/ManagedValueManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,14 @@ protected override bool TryConstructPeer (
284284
}
285285
return base.TryConstructPeer (self, ref reference, options, type);
286286
}
287+
288+
protected override bool TryUnboxPeerObject (IJavaPeerable value, [NotNullWhen (true)]out object? result)
289+
{
290+
var proxy = value as JavaProxyThrowable;
291+
if (proxy != null) {
292+
result = proxy.InnerException;
293+
return true;
294+
}
295+
return base.TryUnboxPeerObject (value, out result);
296+
}
287297
}

0 commit comments

Comments
 (0)