You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Mono.Android] fix "replaceable" objects in ManagedValueManager
The following test is failing on NativeAOT as well as any case we'd
use `ManagedValueManager`:
[Test]
public void JnienvCreateInstance_RegistersMultipleInstances ()
{
using (var adapter = new CreateInstance_OverrideAbsListView_Adapter (Application.Context)) {
var intermediate = CreateInstance_OverrideAbsListView_Adapter.Intermediate;
var registered = Java.Lang.Object.GetObject<CreateInstance_OverrideAbsListView_Adapter>(adapter.Handle, JniHandleOwnership.DoNotTransfer);
Assert.AreNotSame (adapter, intermediate); // Passes
Assert.AreSame (adapter, registered); // Fails!
}
}
With the assertion:
Expected: same as <com.xamarin.android.runtimetests.CreateInstance_OverrideAbsListView_Adapter{cbd0e5a V.ED.VC.. ......I. 0,0-0,0}>
But was: <com.xamarin.android.runtimetests.CreateInstance_OverrideAbsListView_Adapter{cbd0e5a V.ED.VC.. ......I. 0,0-0,0}>
The second assertion fails because `registered` is the same instance
as `intermediate`. In this example, this is a code path where
`intermediate` should be "replaced" with `adapter`.
After lots of debugging, I found the problem are these lines in the
`ManagedValueManager.AddPeer()` method:
var o = PeekPeer (value.PeerReference);
if (o != null)
return;
If we `PeekPeer()` in the middle of `AddPeer()` and a type is
"replaceable", it would find an instance and not replace it! I did not
find equivalent code in `AndroidValueManager.AddPeer()`, which is what
is used in Mono & production today.
With these lines removed, the test passes. I will look if we should
also update these lines in dotnet/java-interop in a future PR.
0 commit comments