Commit dd40c1a
authored
[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#r15049200231 parent 95428f1 commit dd40c1a
File tree
2 files changed
+103
-13
lines changed- src/Mono.Android/Android.Runtime
- tests/Mono.Android-Tests/System
2 files changed
+103
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
40 | 117 | | |
41 | 118 | | |
42 | 119 | | |
| |||
61 | 138 | | |
62 | 139 | | |
63 | 140 | | |
64 | | - | |
65 | 141 | | |
66 | 142 | | |
67 | 143 | | |
68 | 144 | | |
| 145 | + | |
69 | 146 | | |
70 | 147 | | |
71 | 148 | | |
72 | 149 | | |
| 150 | + | |
| 151 | + | |
73 | 152 | | |
74 | | - | |
75 | | - | |
| 153 | + | |
| 154 | + | |
76 | 155 | | |
77 | | - | |
| 156 | + | |
78 | 157 | | |
79 | 158 | | |
80 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
65 | 76 | | |
66 | 77 | | |
67 | | - | |
| 78 | + | |
68 | 79 | | |
69 | 80 | | |
70 | 81 | | |
| |||
0 commit comments