-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java.Interop] Remove JniRuntime.JniValueManager.GetObject()
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=25443 Fixes: dotnet/java-interop#2 Fixes: dotnet/java-interop#3 The problem with JniRuntime.JniValueManager.GetObject() is that it was constrained to only return IJavaPeerable instances. This constraint in turn necessitated the introduction of JniMarshal.GetValue<T>() (commit 1e14a61) so that "anything" could be stored within a JavaObjectArray<T>, proxying values if required. This in turn led to a dichotomy: should JniRuntime.GetObject<T>() be used, or should JniMarshal.GetValue<T>() be used? This dichotomy was partially resolved in commit 77a6bf8, which removed JniMarshal.GetValue<T>() and added a JniRuntime.JniValueManager.GetValue<T>() method, but that just introduced a different dichotomy: should JniValueManager.GetObject() be used or JniValueManager.GetValue()? Simplify this mess: kill JniValueManager.GetObject() (and all overloads), and instead rely on JniValueManager.GetValue(). Additionally, add JniValueManager.CreateValue() overloads (Issue #3) and fix JniValueMarshaler<T>.CreateGenericValue() logic to *not* lookup registered values, as per commit 77a6bf8: > clean[] up JniValueMarshaler.Create*Value() methods to always > create values when able, simplifying the logic of > JniValueMarshaler implementations. Cleaning up these semantics is necessary so that JniValueManager.CreateValue() can be meaningful. The only time that JniValueManager.CreateValue() won't create a *new* value is if the value is a proxy'd instance, at which point we're not going to muck with it and any resulting bugs are Not Our Problem™. The primary change of killing JniValueManager.GetObject() required a few secondary changes: * JniValueManager.RegisterObject<T>() can no longer throw a NotSupportedException when attempting to create an alias, as (1) the NotSupportedException is a semantic change from Xamarin.Android that we can't accept -- aliases are a fact of life, and will be required for .JavaCast<T> (Issue #10) -- and (2) the check was breaking unit tests. We now generate a warning to the GREF log when aliases are created, similar in spirit to what Xamarin.Android does. * ProxyValueMarshaler.CreateGenericValue() now falls back to JniValueManager.CreateObjectWrapper() instead of returning `null`. This was needed so that ValueManager.GetValue<Exception>(...) would work. * For a "unified type system"-like experience, JniValueManager.CreateObjectWrapper() now maps certain types to corresponding types, e.g. object is mapped to JavaObject, and Exception is mapped to JavaException. This is likewise to support ValueManager.GetValue<Exception>(...) around a Java instance.
- Loading branch information
Showing
19 changed files
with
308 additions
and
190 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.