You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Mono.Android] Prevent NullPointerException in TranslateStackTrace (#8795)
Context: #8788 (comment)
Context: 1aa0ea7
The [`java.lang.StackTraceElement(String, String, String, int)`][0]
constructor requires that the `declaringClass` and `methodName`
parameters never be `null`. Failure to do so results in a
`NullPointerException`:
I DOTNET : JavaProxyThrowable: translation threw an exception: Java.Lang.NullPointerException: Declaring class is null
I DOTNET : at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args)
I DOTNET : at Java.Interop.JniPeerMembers.JniInstanceMethods.FinishCreateInstance(String constructorSignature, IJavaPeerable self, JniArgumentValue* parameter s)
I DOTNET : at Java.Lang.StackTraceElement..ctor(String declaringClass, String methodName, String fileName, Int32 lineNumber)
I DOTNET : at Android.Runtime.JavaProxyThrowable.TranslateStackTrace()
I DOTNET : at Android.Runtime.JavaProxyThrowable.Create(Exception innerException)
I DOTNET : --- End of managed Java.Lang.NullPointerException stack trace ---
I DOTNET : java.lang.NullPointerException: Declaring class is null
I DOTNET : at java.util.Objects.requireNonNull(Objects.java:228)
I DOTNET : at java.lang.StackTraceElement.<init>(StackTraceElement.java:71)
I DOTNET : at crc6431345fe65afe8d98.AvaloniaMainActivity_1.n_onCreate(Native Method)
Update `JavaProxyThrowable.TranslateStackTrace()` (1aa0ea7) so that
if `StackFrame.GetMethod()` returns `null`, we fallback to:
1. Trying to extract class name and method name from
[`StackFrame.ToString()`][1]:
MainActivity.OnCreate() + 0x37 at offset 55 in file:line:column <filename unknown>:0:0
2. If (1) fails, pass `Unknown` for `declaringClass` and `methodName`.
Additionally, the `lineNumber` parameter is now set to `-2` if we
think a stack frame points to native code.
[0]: https://developer.android.com/reference/java/lang/StackTraceElement#StackTraceElement(java.lang.String,%20java.lang.String,%20java.lang.String,%20int)
[1]: https://github.com/xamarin/xamarin-android/pull/8758/files#r1504920023
0 commit comments