Bug 8112 - Unable to generate bindings for DroidText: Can't implement IComparable
Summary: Unable to generate bindings for DroidText: Can't implement IComparable
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2012-10-31 16:02 UTC by Jeremy Kolb
Modified: 2012-11-06 05:08 UTC (History)
1 user (show)

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

project (5.90 MB, application/zip)
2012-10-31 16:02 UTC, Jeremy Kolb

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:

Description Jeremy Kolb 2012-10-31 16:02:12 UTC
Created attachment 2825 [details]

When building bindings for DroidText I'm getting errors about classes not implementing Java.Lang.IComparable.  I can see the compareTo method in source and it has the correct signature but the bindings aren't picking it up.  MonoDroid 4.2.7.
Comment 1 Atsushi Eno 2012-11-01 08:36:55 UTC
(This is mostly copy of my post to mono-android mailing list.)

First, you were right, Comparable<T> is (actually Comparable<T> and Comarator<T> are) *special* case that *dropped* compareTo() method from the API description XML. It is to be consistent with the existing AOSP's API definition.

That have been special (at least, regarded so) and as a result it becomes *mandatory* to get CompareTo() method.

And altering interface <implements> element by <attr> in Metadata.xml doesn't work for this case, because unlike binding android.jar java.lang.Comparable<T> cannot be looked up (it needs more investigation to know precise situation, but as a general rule generics don't exist in jar).

Hence, some Metadata.xml fixup has to be done manually, like:

  <add-node path="/api/package/class[implements[@name='java.lang.Comparable']]">
    <method name="compareTo" return="int" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public">
      <parameter name="o" type="java.lang.Object" />
  <add-node path="/api/package/class[implements[@name='java.util.Comparator']]">
    <method name="compare" return="int" abstract="false" native="false" synchronized="false" static="false" final="false" deprecated="not deprecated" visibility="public">
      <parameter name="o1" type="java.lang.Object" />
      <parameter name="o2" type="java.lang.Object" />

It in general falls to "generics only partially supported" category of binding limitations, but the recipe to deal with is slightly different, which we weren't fully aware. So far please take this as a normative way. Sorry for the missing information.

There are two other issues:

1) You will have to rename "harmony.java.lang" to something different, because it brings conflict between "Java.Lang" and "Harmony.Java.Lang" which has never been expected. This will be fixed in the next release but so far this is a limitation.

2) There are some issues regarding detecting not-supported (and hence missing) base types. In this library, com.lowagie.text.Phrase and com.lowagie.text.Section are derived from java.util.ArrayList, which does not exist in Mono.Android.dll and hence not supported.

There is no remedy for missing base type, so they have to be removed (binding generator automatically does it when it correctly detects missing base type):

  <remove-node path="/api/package[@name='com.lowagie.text']/class[@name='Phrase']" />
  <remove-node path="/api/package[@name='com.lowagie.text']/class[@name='Section']" />

(This is a bug and recorded as #8134.)

After fixing those issues, it should be successfully bound.
Comment 2 Atsushi Eno 2012-11-01 10:27:24 UTC
I was wrong on the 2) issue: the base class java.util.ArrayList is replaced by Android.Runtime.JavaList class and the missing Add method issue could be *fixed*. I'll keep posting updates on bug #8134, not here.
Comment 3 Atsushi Eno 2012-11-02 04:28:53 UTC
1) should be fixed as well, we prefix global:: to any Java.Lang occurence to not conflict with *.Java.Lang namespace.
Comment 4 Atsushi Eno 2012-11-06 05:08:31 UTC
This is fixed and will be reflected *after* our next release. Comparable.compareTo(Object) and Comparator.compare(Object,Object) are not special case and our API analyzer won't skip these *necessary* compareTo() methods in the resulting API XML, while it won't generate any extraneous "generics-erased" version of the method overloads anymore. That is, there will be only one compareTo() and compare() whether you specify generic <implements> name or not.

Though with this fix, we will have ask you to apply the workaround at comment #1 ONLY UNTIL this fix lands. With the fixed version, this metadata fixup will result in duplicate methods and will cause error or warning (sorry for inconvenience).

[master 926c7bf]