-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack trace keeps getting longer when an exception instance that is propagated through both Java and managed code is thrown and handled repeatedly #4987
Comments
Wow thank you so much @brendanzagaeski to go deep down and investigate this :) |
This is probably a "won't fix", as I can't think of a fix that won't cause more problems than it solves. First, why is the exception growing in the first place? The exception message grows because our exception marshaling code uses IntPtr thrown;
var tmp = NativeMethods.java_interop_jnienv_new_object_array (JniEnvironment.EnvironmentPointer, out thrown, length, elementClass.Handle, initialElement.Handle);
Exception __e = JniEnvironment.GetExceptionForLastThrowable (thrown);
if (__e != null)
ExceptionDispatchInfo.Capture (__e).Throw (); Because ExceptionDispatchInfo.Capture (STOP_EXCEPTION).Throw (); The use of The fundamental question is, how do we fix this? I don't know of any way to check if an exception has already been logged, and even if there were it might not be a good idea to use such a mechanism! Consider a Java > Managed > Java > Managed > Java > Managed stack trace. If the rightmost stack frame throws an exception which is caught by the leftmost stack frame, you want to see the intervening managed frames! I suppose a fix could be to use |
Context: #4632 (comment)
Steps to reproduce
Create a new Android App (Xamarin) > Single View App.
Similar to Fix XA_BROKEN_EXCEPTION_TRANSITIONS support #4548 (comment), add the following C# class:
And add the following in a JavaRunner.java file with the Build Action set to AndroidJavaSource:
Add the following to the
FabOnClick()
method:Launch the app without the debugger attached.
Monitor the
adb logcat 'mono-stdout:* *:S'
output.Tap the envelope icon button in the lower right of the app screen a few times.
Expected behavior
The
catch
block should produce the same output every time:Actual behavior
The stack trace in the
catch
block output gets longer each time it runs.First time:
Second time:
Third time:
Partial workaround
Change
CSharpThrows.Run()
to create a new instance ofStopException
each time it is invoked:This is only a partial workaround because in other contexts, like calling
CSharpThrows.Run()
directly fromFabOnClick()
, the stack trace behaves as expected without this workaround, so some user code might have scenarios where creating newStopException
instances on eachthrow
is not desirable.Version information
Xamarin.Android SDK 11.0.99.9 (d16-8/2bd5c33)
Testing device: arm64-v8a Android 9.0 Pie (API level 28) Google Pixel 3
The text was updated successfully, but these errors were encountered: