Commit 0fc4b61
[Java.Interop-Tests] Fix JniTypeTest.Name() missing argument (#538)
Context: dotnet/android#3393
When running the `JniTypeTest.Name()` unit test within Xamarin.Android,
sometimes the unit test runner process would crash. The crash is
*more* likely in Release runtimes:
F o.Android_Test: java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xc58fa798
F o.Android_Test: java_vm_ext.cc:570] from void crc64f295cabbf85394f5.TestSuiteInstrumentation.n_onStart()
F o.Android_Test: runtime.cc:630] Runtime aborting...
What was particularly odd about this crash was that after enabling
both GREF and LREF logging, there was no handle 0xc58fa798!
Where was this invalid handle coming from?
Turns Out™, 0xc58fa798 isn't a handle. Instead, it's a parameter
mismatch!
Commit 9f380eb had a bug. `JniTypeTest.Name()` was *attempting* to do:
// Java
java.lang.reflect.Method Object_hashCode = Object.class.getMethod("hashCode", new Class[0]);
String Object_hashCode_returnType = Object_hashCode.getReturnType();
However, via JNI, it was *actually* doing:
java.lang.reflect.Method Object_hashCode = Object.class.getMethod("hashCode", GARBAGE_VALUE);
String Object_hashCode_returnType = Object_hashCode.getReturnType();
because it was only passing *one* value to `Class.getMethod()`, not
two values, so the second parameter was entirely undefined and
unknowable.
Through sheer luck (or a terrible bug) this "worked" on a Desktop JVM
and (frequently) in Debug configuration builds of the
`Mono.Android_Tests-*.apk` test app in Xamarin.Android.
On Android in a Release configuration, GARBAGE_VALUE was treated as a
garbage value, and brought down the process because there *was*, in
fact, a JNI error in the application.
Fix `JniTypeTest.Name()`, and pass the correct number of parameters to
`Class.getMethod(String, Class[])`.
Additionally, make two (mostly unrelated) changes:
* Add a `JniType.ToString()` override.
* Change the exception ordering in `JavaExceptionTests.StackTrace().
While debugging the above crash, I attempted to use
`JniType.ToString()` in some debug messages. These were useless,
because there was no `JniType.ToString()` override.
Add one.
The conceptual problem `JavaExceptionTests.StackTrace()`, meanwhile,
is that *eventually* `Java.Lang.Throwable` will be updated to inherit
from `Java.Interop.JavaException`. If `JavaException` is caught
first, then the `__ANDROID__`-specific behavior around
`Java.Lang.Throwable` will no longer be tested, *and* the test will
continue to pass (while testing subtly different behavior). Reorder
the `catch` blocks so that when the `Java.Lang.Throwable` base class
changes, the semantics of the test will be unaltered.1 parent 0065de4 commit 0fc4b61
File tree
3 files changed
+21
-11
lines changed- src/Java.Interop/Java.Interop
- tests/Java.Interop-Tests/Java.Interop
3 files changed
+21
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| |||
Lines changed: 10 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | | - | |
28 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
| 37 | + | |
35 | 38 | | |
36 | | - | |
| 39 | + | |
37 | 40 | | |
38 | | - | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
145 | | - | |
146 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| 159 | + | |
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
| |||
0 commit comments