Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ee565e4
Improve JavaProxyThrowable by translating managed stack trace
grendello Jul 12, 2023
7c0a507
Update apkdiffs
grendello Jul 12, 2023
6ee31a3
Create JavaProxyThrowable with `Create` and reflection
grendello Jul 12, 2023
7cfc3dc
Oops
grendello Jul 12, 2023
78839fb
Seal the class and add test
grendello Jul 13, 2023
b2b38b1
Merge branch 'main' into throwable-stacktrace
grendello Jul 14, 2023
ada140c
Optionally append java stack trace
grendello Jul 14, 2023
45b3e72
oops
grendello Jul 14, 2023
241ed9b
Merge branch 'main' into throwable-stacktrace
grendello Jul 17, 2023
c1cabbc
oops #2
grendello Jul 17, 2023
4c38c11
Let's see if this works
grendello Jul 17, 2023
7a8964b
Java and managed traces differ, let's see what's the difference
grendello Jul 17, 2023
1bac358
Merge branch 'main' into throwable-stacktrace
grendello Jul 18, 2023
998c012
That should do it
grendello Jul 18, 2023
a25636d
Merge branch 'main' into throwable-stacktrace
grendello Jul 18, 2023
92e5db3
Merge branch 'main' into throwable-stacktrace
grendello Jul 24, 2023
4b5b56e
Update JavaProxyThrowable.cs
grendello Jul 26, 2023
b68dcc2
Merge branch 'main' into throwable-stacktrace
grendello Jul 27, 2023
32130ab
Get the Java stack trace from `self` directly
grendello Jul 27, 2023
603f1e4
Merge branch 'throwable-stacktrace' of github.com:grendello/xamarin-a…
grendello Jul 27, 2023
cdf4714
Merge branch 'main' into throwable-stacktrace
grendello Jul 31, 2023
784014c
Address comments
grendello Jul 31, 2023
a78d466
Merge remote-tracking branch 'origin/main' into throwable-stacktrace
jonpryor Aug 18, 2023
691e075
Update ExceptionTest.cs
jonpryor Aug 22, 2023
af90f92
Fix unit test.
jonpryor Aug 22, 2023
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
Prev Previous commit
Next Next commit
That should do it
  • Loading branch information
grendello committed Jul 18, 2023
commit 998c0121fc684c24e054b9355ed0f892cc7d402b
9 changes: 6 additions & 3 deletions src/Mono.Android/Android.Runtime/JavaProxyThrowable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public static JavaProxyThrowable Create (Exception? innerException, bool appendJ

try {
proxy.TranslateStackTrace (appendJavaStackTrace);
} catch {
} catch (Exception ex) {
// We shouldn't throw here, just try to do the best we can do
Console.WriteLine ($"JavaProxyThrowable: translation threw an exception: {ex}");
proxy = new JavaProxyThrowable (innerException.ToString (), innerException);
}

Expand All @@ -46,8 +47,10 @@ void TranslateStackTrace (bool appendJavaStackTrace)
if (appendJavaStackTrace) {
try {
javaTrace = Java.Lang.Thread.CurrentThread ()?.GetStackTrace ();
} catch {
// Ignore
} catch (Exception ex) {
// Report...
Console.WriteLine ($"JavaProxyThrowable: obtaining Java stack trace threw an exception: {ex}");
// ..but ignore
}
}

Expand Down
17 changes: 4 additions & 13 deletions tests/Mono.Android-Tests/System/ExceptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public void InnerExceptionIsSet ()
ex = e;
}

using (var source = new Java.Lang.Throwable ("detailMessage", CreateJavaProxyThrowable (ex)))
using (Java.Lang.Throwable proxy = CreateJavaProxyThrowable (ex))
using (var source = new Java.Lang.Throwable ("detailMessage", proxy))
using (var alias = new Java.Lang.Throwable (source.Handle, JniHandleOwnership.DoNotTransfer)) {
CompareStackTraces (ex, source);
CompareStackTraces (ex, proxy);
Assert.AreEqual ("detailMessage", alias.Message);
Assert.AreSame (ex, alias.InnerException);
}
Expand All @@ -53,18 +54,8 @@ void CompareStackTraces (Exception ex, Java.Lang.Throwable throwable)
StackFrame[] managedFrames = managedTrace.GetFrames ();
Java.Lang.StackTraceElement[] javaFrames = throwable.GetStackTrace ();

System.Console.WriteLine ("Managed stack trace:");
foreach (StackFrame sf in managedFrames) {
System.Console.WriteLine ($" {sf}");
}

System.Console.WriteLine ("Java stack trace:");
foreach (Java.Lang.StackTraceElement ste in javaFrames) {
System.Console.WriteLine ($" {ste}");
}

// Java
Assert.AreEqual (managedFrames.Length, javaFrames.Length - 2, "Java and managed stack traces have a different number of frames");
Assert.AreEqual (managedFrames.Length, javaFrames.Length, "Java and managed stack traces have a different number of frames");
for (int i = 0; i < managedFrames.Length; i++) {
var mf = managedFrames[i];
var jf = javaFrames[i];
Expand Down