For some reason we crash when we pass a zero jni handle to native.
Is this a crash in dalvik or our code? If it's in our code, we better fix it.
If it's in dalvik, we better offer to handle it under some configuration/option as the native crash makes us look bad
and there are cases where user code bug can trigger this.
It doesn't help if we crash if an user call methods on disposed objects.
> Is this a crash in dalvik or our code?
> If it's in dalvik, we better offer to handle it under some configuration/option
> as the native crash makes us look bad
Do you have any suggestions on what we should do?
Some cursory suggestions:
1. Make Java.Lang.Object.Handle throw if it's IntPtr.Zero
2. JNIEnv.Call*Method() can check for a null `this` pointer, then
2.a) Generate a warning, then ignore the call
2.b) Generate a warning and abort the process
> It doesn't help if we crash if an user call methods on disposed objects.
I'm less caring if someone explicitly disposes of an object and then things blow up:
var o = new Java.Lang.Object();
string s = o.ToString(); // BOOM
However, if/when the GC collects the instance (GC bugs! See Bug #13858 and Bug #14999), things get more confusing.
To return to the "cursory suggestions":
The problem with (1) is that, while it sounds fairly clean (calling a method on an invalidated object would crash the process with an unhandled exception, with a plausibly useful message), it has a flaw:
It provides no way for the user to manually workaround GC bugs unless they use try/catch.
(I suppose this could be opt-in via AndroidEnvironment...)
(2a) just sounds evil.
(2b) should be reasonably easy to do.
monodroid/c71b6125 implements (3): JNIEnv.* methods null-check their arguments and will throw an ArgumentException or ArgumentNullException if IntPtr.Zero or null is passed when it is inappropriate.
Consequently, `o.ToString()` now results in an ArgumentException instead of a process abort.
Keeping this open in case we need to discuss alternatives.