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
JNI logs as "UNHANDLED EXCEPTION" an handled exception #4632
Comments
Hi, I just tried to reproduce this locally (VSMac) and, please confirm if I'm wrong, but I believe I got the expected behavior: I'm using VSMac with the following version of the product: https://gist.github.com/VincentDondain/7e38ef531ffb97c69dfb874ad71d420b So either this is a VS Windows specific issue or it's been fixed in the .6 series. @roubachof have you tried with the .6 series? https://devblogs.microsoft.com/visualstudio/visual-studio-2019-version-16-6-preview-2/
|
Note: https://github.com/roubachof/Sharpnado.Presentation.Forms in the The issue described is about non debugging situation. The debugging issue (causing SIGSEGV) is already opened #4548. The StopException is in fact handled here: try
{
blurView.mBlurringCanvas.Scale(
1f * blurView.mBitmapToBlur.Width / blurView.Width,
1f * blurView.mBitmapToBlur.Height / blurView.Height);
blurView.mBlurringCanvas.Translate(-x, -y);
if (decor.Background != null)
{
decor.Background.Draw(blurView.mBlurringCanvas);
}
decor.Draw(blurView.mBlurringCanvas);
}
catch (StopException)
{
// code here is executed as well, giving the exception a Schrödinger cat semantic
// (both caught and unhandled :)
} As you can see the |
Hi, would it be possible to see if anyone could investigate this issue? @roubachof has created the fantastic MaterialFrame library which is being used in a real world application. However, this issue seems to be causing some sort of a memory leak which quickly makes the application grind to a halt and make it effectively unusable. If this cannot be resolved, it would mean that his library would not be truly usable by anyone and it would also require a significant portion of our UI to be rewritten. It would really be great if someone could investigate this for us, as it really would be shame to see all the hard work that @roubachof has put into this library go to waste. |
To be more precised, it doesn't seem to be a memory leak, but more the giant spam of Unhandled Exception stack that floods the logs and seems to cause the sluggishness. |
Another issue appeared on top of that since the UNHANDLED EXCEPTION stack seems to get bigger and bigger with each occurrence of the exception. |
Smaller reproduction steps
(Edit: Adding example results from this smaller test scenario.) Actual resultsAfter step 4, the
If I add the following line to
I can see more about the transitions between managed and Java:
There isn't anything particularly surprising there, but it helps confirm that the scenario involves an exception that propagates from managed to Java and then back to managed before the |
Alternative minimal steps to reproduce(Steps without a dependency on
|
Handled exceptions result in "UNHANDLED EXCEPTION" printed to
What's the fix? We need to keep the xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.cs Lines 265 to 293 in d44e48a
|
Fixes: xamarin#4632 The `UNHANDLED EXCEPTION` message was printed from `AndroidEnvironment.UnhandledException()`, which is invoked during exception propagation, at each Managed::Java VM boundary. It need not be from an *actual* unhandled exception! Consequently, if there is a Managed :: Java :: Managed stack frame, and *either* the 1st Managed or the Java frames catch the exception thrown from the 2nd Managed frame -- meaning the exception is in fact handled! -- we would still "spam" `adb logcat` with `UNHANDLED EXCEPTION` messages, because at the "scope" in which it's emitted, it can't know whether or not it's *actually* unhandled. To avoid spamming `adb logcat` with unecessary noise, move the `UNHANDLED EXCEPTION` log message into `JNIEnv.PropagateUncaughtException()`. This method is invoked *only* when there is a *Java-side* unhandled exception, via [`java.lang.Thread.setUncaughtExceptionHandler()`][0] and [`java.lang.Thread.UncaughtExceptionHandler.uncaughtException()`][1]. [0]: https://developer.android.com/reference/java/lang/Thread#setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) [1]: https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread,%20java.lang.Throwable)
Would it explain why in the following issue roubachof/Sharpnado.MaterialFrame#7 (comment), the exception stack is getting bigger and bigger? |
Fixes: #4632 The `UNHANDLED EXCEPTION` message was printed from `AndroidEnvironment.UnhandledException()`, which is invoked during exception propagation, at each Managed::Java VM boundary. It need not be from an *actual* unhandled exception! Consequently, if there is a Managed :: Java :: Managed stack frame, and *either* the 1st Managed or the Java frames catch the exception thrown from the 2nd Managed frame -- meaning the exception is in fact handled! -- we would still "spam" `adb logcat` with `UNHANDLED EXCEPTION` messages, because at the "scope" in which it's emitted, it can't know whether or not it's *actually* unhandled. To avoid spamming `adb logcat` with unecessary noise, move the `UNHANDLED EXCEPTION` log message into `JNIEnv.PropagateUncaughtException()`. This method is invoked *only* when there is a *Java-side* unhandled exception, via [`java.lang.Thread.setUncaughtExceptionHandler()`][0] and [`java.lang.Thread.UncaughtExceptionHandler.uncaughtException()`][1]. [0]: https://developer.android.com/reference/java/lang/Thread#setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) [1]: https://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread,%20java.lang.Throwable)
I have submitted a new issue #4987 for the behavior where the stack trace gets longer on repeated uses of an exception instance. Release status update for the UNHANDLED EXCEPTION fix A new Preview version of Xamarin.Android has now been published that includes the fix for this item that addresses the behavior where these handled exceptions were appearing in the app log output as UNHANDLED EXCEPTION. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix. Fix included in Xamarin.Android SDK version 11.0.99.9. Fix included on Windows in Visual Studio 2019 version 16.8 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview. Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel. |
Release status update for the UNHANDLED EXCEPTION fix A new Release version of Xamarin.Android has now been published that includes the fix for this item that addresses the behavior where these handled exceptions were appearing in the app log output as UNHANDLED EXCEPTION. Fix included in Xamarin.Android SDK version 11.1.0.17. Fix included on Windows in Visual Studio 2019 version 16.8. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/. Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stable updater channel. |
I split this issue from the original one #4548 since this is in fact 2 different issues.
JNI considers a perfectly caught exception as an unhandled exception.
If in
RELEASE
or ran inDEBUG
mode without debugging, anUNHANDLED EXCEPTION
is raised in the log, but the app doesn't crash.Here is my scenario:
The exception is handled in the try catch as a
StopException
, so why JNI thinks it's unhandled ?In pure Java world the
StopException
wouldn't be considered as an uncaught exception, but in the Xamarin context, it does.Details
I am here trying to create blur views for
Xamarin.Forms
, for the android implementation I chose https://github.com/mmin18/RealtimeBlurView.I translated in C# all the classes, you can find them here:
https://github.com/roubachof/Sharpnado.Presentation.Forms/tree/secret/Sharpnado.Presentation.Forms.Droid/Renderers/MaterialFrame/RealtimeBlurView
In his java implementation, mmin18 has the following code:
https://github.com/mmin18/RealtimeBlurView/blob/master/library/src/com/github/mmin18/widget/RealtimeBlurView.java#L259-L267
For stoping the drawing process he throws a custom "STOP_EXCEPTION" in the
Draw
method of the blur view:https://github.com/mmin18/RealtimeBlurView/blob/master/library/src/com/github/mmin18/widget/RealtimeBlurView.java#L321-L330
Remark: you have to interrupt the drawing of all the next children, so returning in the blur view's Draw method is not enough....
Steps to Reproduce
Expected Behavior
No
UNHANDLED EXCEPTION
should be raised and logged.Actual Behavior
Version Information
Microsoft Visual Studio Community 2019
Version 16.5.2
VisualStudio.16.Release/16.5.2+29926.136
Microsoft .NET Framework
Version 4.8.03752
Installed Version: Community
Visual C++ 2019 00435-60000-00000-AA963
Microsoft Visual C++ 2019
ASP.NET and Web Tools 2019 16.5.236.49856
ASP.NET and Web Tools 2019
ASP.NET Web Frameworks and Tools 2019 16.5.236.49856
For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 16.5.236.49856
Azure App Service Tools v3.0.0
Azure Functions and Web Jobs Tools 16.5.236.49856
Azure Functions and Web Jobs Tools
C# Tools 3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Extensibility Message Bus 1.2.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
Fabric.DiagnosticEvents 1.0
Fabric Diagnostic Events
IntelliCode Extension 1.0
IntelliCode Visual Studio Extension Detailed Info
JetBrains ReSharper Ultimate 2019.3.4 Build 193.0.20200226.112949
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2020 JetBrains, Inc.
Microsoft Azure Service Fabric Tools for Visual Studio 16.0
Microsoft Azure Service Fabric Tools for Visual Studio
Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30207.1
Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft Library Manager 2.1.25+gdacdb9b7a1
Install client-side libraries easily to any web project
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards
Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio 16.5.514 (c4f36a9)
Support for debugging Mono processes with Visual Studio.
NuGet Package Manager 5.5.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
ResXManager 1.40.3444.0
Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid.
SettingsWindow Extension 1.0
SettingsWindow Visual Studio Extension Detailed Info
SQL Server Data Tools 16.0.62003.05170
Microsoft SQL Server Data Tools
StylerPackage Extension 1.0
StylerPackage Visual Stuido Extension Detailed Info
TypeScript Tools 16.0.20225.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 3.5.0-beta4-20153-05+20b9af913f1b8ce0a62f72bea9e75e4aa3cf6b0e
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.8.0.0 for F# 4.7 16.5.0-beta.20104.8+7c4de19faf36647c1ef700e655a52350840c6f03
Microsoft Visual F# Tools 10.8.0.0 for F# 4.7
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Container Tools Extensions (Preview) 1.0
View, manage, and diagnose containers within Visual Studio.
Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers
Visual Studio Tools for Kubernetes 1.0
Visual Studio Tools for Kubernetes
VisualStudio.DeviceLog 1.0
Information about my package
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
Xamarin 16.5.000.528 (d16-5@2b54082)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 16.5.0.470 (remotes/origin/d16-5@681de3fd6)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin Templates 16.5.49 (0904f41)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 10.2.0.100 (d16-5/988c811)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: c0c5c78
Java.Interop: xamarin/java.interop@fc18c54
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools@9f4ed4b
Xamarin.iOS and Xamarin.Mac SDK 13.16.0.11 (aa73e41)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
The text was updated successfully, but these errors were encountered: