Skip to content

Conversation

@jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Jul 26, 2019

Context: dotnet/android#3393

Allow the Java.Interop unit tests to be consumed by Xamarin.Android.

In particular, this means:

  • "Proper" exceptions such as Java.Lang.ClassNotFoundException are
    thrown, not "based" JavaException types.

  • Xamarin.Android.NUnitLite.dll doesn't provide
    [OneTimeSetUpAttribute]/etc., so use
    [TestFixtureSetUpAttribute] instead.

  • Xamarin.Android doesn't currently support
    Java.Interop.MarshalMemberBuilder, so any tests which require it
    will not work. "Hide" those behind
    #if !NO_MARSHAL_MEMBER_BUILDER_SUPPORT.

Context: TODO

Allow the Java.Interop unit tests to be consumed by Xamarin.Android.

In particular, this means:

  * "Proper" exceptions such as `Java.Lang.ClassNotFoundException` are
    thrown, not "based" `JavaException` types.

  * `Xamarin.Android.NUnitLite.dll` doesn't provide
    `[OneTimeSetUpAttribute]`/etc., so use
    `[TestFixtureSetUpAttribute]` instead.

  * Xamarin.Android doesn't currently support
    `Java.Interop.MarshalMemberBuilder`, so any tests which require it
    will not work.  "Hide" those behind
    `#if !NO_MARSHAL_MEMBER_BUILDER_SUPPORT`.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Jul 26, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * Merge dotnet/java-interop#454 and stop
    using the jonpryor/Java.Interop/jonp-xa-integration branch.

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
@jonpryor jonpryor merged commit be58159 into dotnet:master Jul 29, 2019
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 6, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 7, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 9, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 9, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 10, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Sep 11, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Oct 31, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Nov 10, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Nov 13, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Nov 20, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Nov 22, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Nov 27, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Dec 12, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Dec 16, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Dec 17, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
jonpryor added a commit to jonpryor/xamarin-android that referenced this pull request Dec 20, 2019
Context: dotnet/java-interop#454
Context: https://github.com/xamarin/monodroid/commit/e318861e
Context: dotnet@7d32ef3e6
Context: dotnet@1a2eb95

When use of `Java.Interop.dll` was originally added in
xamarin/monodroid@e318861e, it didn't implement the "full"
`JniRuntime` abstraction, which meant that until
dotnet/android@1a2eb953, trying to instantiate a
`JavaInt32Array` instance would result in a `NotImplementedException`,
because `Android.Runtime.AndroidValueManager.AddPeer()` threw a
`NotImplementedException`.

Commit dotnet/android@1a2eb953 removed the exception but
didn't *implement* `JniRuntime.JniValueManager.AddPeer()`, meaning
even though a `JavaInt32Array` could be *instantiated*, it wouldn't
*work* "properly", e.g. `JniRuntime.JniValueManager.PeekPeer()`
wouldn't *find* the `JavaInt32Array` when given the same handle.

This in turn "happened" because `Mono.Android-Tests.dll` never
*executed* the unit tests for `Java.Interop.dll`, which it *couldn't*
do, because it didn't fully support the semantics.

Add the `Java.Interop.dll` unit tests to `Mono.Android-Tests.dll`, and
fix `Mono.Android.dll` and company so that they can actually *pass*:

  * Add a new `Java.Interop-Tests.csproj` project to "host" the
    Java.Interop unit tests in a MonoAndroid-profile project.

  * Add `java-interop.jar` to the `javac` command line generated by
    `Jar.targets`, so that e.g. `com.xamarin.java_interop.ManagedPeer`
    can be used.

  * Update `Mono.Android.dll` so that the Java.Interop unit tests
    work.  This includes "migrating" the (jobject => instance) mapping
    previously accessible via `Java.Lang.Object.GetObject<T>()` into
    `Android.Runtime.AndroidValueManager`.

  * `AndroidRuntime.GetExceptionForThrowable()` will now "unwrap" a
    `Java.Interop.JavaProxyThrowable` instance.

  * `AndroidTypeManager.GetSimpleReferences()` can't use
    `JNIEnv.GetJniName()` because that always returns
    `java/lang/Object`, even if a type can't be found, which breaks
    several Java.Interop unit tests.  Use
    `JNIEnv.monodroid_typemap_managed_to_java()` instead.

  * `AndroidTypeManager.RegisterNativeMembers()` will now invoke
    `JniRuntime.JniTypeManager.RegisterNativeMembers()` when `methods`
    is empty, so that classes can handle their own registration.  This
    was needed so that
    `Java.InteropTests.CallVirtualFromConstructorDerived` could
    actually be properly instantiated and participate in tests.

  * `Java.Interop.TypeManager.CreateProxy()` now supports
    Java.Interop-style
    `(ref JniObjectReference, JniObjectReferenceOptions)`
    constructors.

  * `Java.Interop.JavaObject` and `Java.Interop.JavaException` are now
    bridgeable types, and can participate in GC's.

    This means that e.g. `JavaInt32Array` instances won't be
    prematurely collected.

TODO:

  * `Java.Lang.Object` should be updated to inherit from
    `Java.Interop.JavaObject`

  * `Java.Lang.Throwable` should be updated to inherit from
    `Java.Interop.JavaException`

  * `generator` needs to be updated to begin *avoiding* the `JNIEnv`
    methods, so that non-`Java.Lang.*`-inheriting types can be used.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant