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] JavaList.Add should allow duplicates. (#9751)
Fixes: #9675
Context: https://github.com/xamarin/monodroid/commit/0e782afc16fe4b7197c800864d6c10520905fe28
Context: https://github.com/xamarin/monodroid/commit/8d38265ba00678ff3f3dd6edd8ceb10a97b55abd
Context: https://github.com/xamarin/monodroid/commit/be4087f038957a36a0bb3b9f9dc401c65ef379ca
Binding is a historically hairy business, and sometimes we live with
the results of those choices decades later.
Case in point: what should be done about `java.util.List<E>`?
Some time around 2010-Sep-7 in xamarin/monodroid@0e782afc was a
"Generic and Collections restructuring", which resulted in the
*removal* of `java.util.List` and other interfaces from
`Mono.Android.dll`. The idea was that bindings would instead use
`Android.Runtime.JavaList` and other types instead.
This was the continued state of affairs when [Bugzilla 8112][0] was
filed, which was an issue binding DroidText, which was simplified
into [Bugzilla 8134][1]. The underlying problem was that some type
in DroidText implemented `java.util.List`, which wasn't bound and
instead was replaced with `JavaList`, but the generated bindings
would attempt to override and implement `java.util.List` methods
such as `Add()` on `JavaList`, which didn't exist, resulting in
compilation errors.
The fix in 2012-Nov-2 in xamarin/monodroid@8d38265b was to add all
`java.util.List` methods onto `JavaList`. Fair enough, but this was
also a time with minimal code review, and the fix has a couple of
obvious problems in retrospect:
partial class JavaList {
public virtual bool Add (int index, Java.Lang.Object item)
{
if (Contains (item))
return false;
Add ((object) item);
return true;
}
public virtual bool Add (Java.Lang.Object item)
{
return Add (0, item);
}
}
Firstly, why is `Add(int, Object)` calling `Contains(item)`?
This meant that duplicate values couldn't be added, even though that
is something that Java would allow.
Secondly, why is `Add(int index, Object item)` *ignoring* the
`index` parameter?
Thirdly, why is `Add(Object)` always inserting at index 0?
That doesn't really make sense, and the only reason it hasn't
resulted in `JavaList.Add()` invocations resulting in *reversing* the
order of `Add()` calls is because the `0` was ignored (2).
Fix all three of these issues.
The underlying problem of "`java.util.List` isn't bound!" was later
resolved in 2013-Mar-11 by xamarin/monodroid@be4087f0, which stopped
removing `java.util.List` from `Mono.Android.dll`.
[0]: https://web.archive.org/web/20210922182648/https://bugzilla.xamarin.com/81/8112/bug.html
[1]: https://web.archive.org/web/20210925214551/https://bugzilla.xamarin.com/81/8134/bug.html
0 commit comments