-
Notifications
You must be signed in to change notification settings - Fork 63
[Java.Interop-Tests] Fix JniTypeTest.Name() missing argument #538
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 12, 2019
Context: dotnet/java-interop#538 Should fix the `JNI DETECTED ERROR IN APPLICATION` crash which was preventing the unit tests from completing successfully.
jpobst
approved these changes
Dec 12, 2019
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 12, 2019
Context: dotnet/java-interop#538 Should fix the `JNI DETECTED ERROR IN APPLICATION` crash which was preventing the unit tests from completing successfully.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 12, 2019
dotnet/java-interop#538 was merged, so d80020f is no longer necessary.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 16, 2019
Context: dotnet/java-interop#538 Should fix the `JNI DETECTED ERROR IN APPLICATION` crash which was preventing the unit tests from completing successfully.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 16, 2019
dotnet/java-interop#538 was merged, so d80020f is no longer necessary.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 17, 2019
Context: dotnet/java-interop#538 Should fix the `JNI DETECTED ERROR IN APPLICATION` crash which was preventing the unit tests from completing successfully.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 17, 2019
dotnet/java-interop#538 was merged, so d80020f is no longer necessary.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 20, 2019
Context: dotnet/java-interop#538 Should fix the `JNI DETECTED ERROR IN APPLICATION` crash which was preventing the unit tests from completing successfully.
jonpryor
added a commit
to jonpryor/xamarin-android
that referenced
this pull request
Dec 20, 2019
dotnet/java-interop#538 was merged, so d80020f is no longer necessary.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:However, via JNI, it was actually doing:
because it was only passing one value to
Class.getMethod()
, nottwo 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 toClass.getMethod(String, Class[])
.Additionally, make two (mostly unrelated) changes:
JniType.ToString()
override.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 inheritfrom
Java.Interop.JavaException
. IfJavaException
is caughtfirst, then the
__ANDROID__
-specific behavior aroundJava.Lang.Throwable
will no longer be tested, and the test willcontinue to pass (while testing subtly different behavior). Reorder
the
catch
blocks so that when theJava.Lang.Throwable
base classchanges, the semantics of the test will be unaltered.