Bug 58303 - Java.Util.HashMap is mapped to Android.Runtime.JavaDictionary in binding generator
Summary: Java.Util.HashMap is mapped to Android.Runtime.JavaDictionary in binding gene...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.3 (15.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: 15.4
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2017-07-21 18:58 UTC by Bill Holmes
Modified: 2017-08-15 18:45 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Jar file to reproduce the bug (1.13 KB, application/java-archive)
2017-07-21 18:58 UTC, Bill Holmes
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Bill Holmes 2017-07-21 18:58:41 UTC
Created attachment 23724 [details]
Jar file to reproduce the bug

Create a binding project from the attached jar file.  

When you build you will get 11 errors stating that the JSONObject does not implement interface member IMap....

Many of the missing members are a part of the java.util.HashMap class which is the base class of JSONObject in the Java world.

However the binding generator decided to change the base class to Android.Runtime.JavaDictionary.  

I can not find a way to disable this behavior and question if it is even the correct change to make.
Comment 1 Bill Holmes 2017-07-21 19:01:17 UTC
Link to the Components project that is actually experiencing the problem. 

DropboxCoreApi for Android
https://github.com/xamarin/XamarinComponents/tree/master/XPlat/DropboxCoreApi/Android
Comment 3 Jon Douglas [MSFT] 2017-07-21 19:21:16 UTC
I can CONFIRM this behavior:

https://gist.github.com/JonDouglas/cef2d3f103dba7dd22018360dfc9685f#file-gistfile1-txt-L5844-L5854

Here's the api.xml

<class abstract="false" deprecated="not deprecated" extends="java.util.HashMap" extends-generic-aware="java.util.HashMap" final="false" name="JSONObject" static="false" visibility="public">
<implements name="java.util.Map" name-generic-aware="java.util.Map">
</implements>
<constructor deprecated="not deprecated" final="false" name="JSONObject" static="false" type="com.example.mylibrary56345345.JSONObject" visibility="public">
</constructor>
</class>

However the generated class is the following:

public partial class JSONObject : global::Android.Runtime.JavaDictionary, global::Java.Util.IMap

Thus it seems like it should be Java.Util.HashMap instead as per https://bugzilla.xamarin.com/show_bug.cgi?id=58303#c0
Comment 4 Jonathan Pryor 2017-08-08 14:19:34 UTC
This appears to be the "mirror" of Bug #56436: `generator` behavior is dependent on the order of types in an assembly (`Mono.Android.dll` in this case), and if that order changes, weird things happen:

> For example, if an assembly defines `JavaCollection` before
> `ICollection`, then a type lookup for `java.util.Collection` will
> return `ICollection`. If instead the assembly defines `ICollection`
> before `JavaCollection`, then a type lookup for `java.util.Collection`
> will instead return `JavaCollection`.
> 
> This is not necessarily desirable, but I don't see much alternative.

Looks like I'll need to think up an alternative.
Comment 5 Jonathan Pryor 2017-08-09 18:55:08 UTC
In the absence of an alternative, the easier solution is probably fixing up `Mono.Android.dll` to ensure that e.g. `Java.Util.HashMap` is defined *after* `Android.Runtime.JavaDictionary`.
Comment 6 Jonathan Pryor 2017-08-11 16:40:16 UTC
PR: https://github.com/xamarin/xamarin-android/pull/741