Bug 41195 - Binding an interface that inherits from an interface with generics
Summary: Binding an interface that inherits from an interface with generics
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2016-05-19 21:14 UTC by Matthew Leibowitz
Modified: 2016-08-17 06:47 UTC (History)
2 users (show)

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

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 Matthew Leibowitz 2016-05-19 21:14:57 UTC
I have a Java interface `HandlerExecutorService` that inherits from `java.util.concurrent.ScheduledExecutorService`. When binding this interface, the generator emits this on the `IHandlerExecutorServiceInvoker` invoker:

IntPtr id_shutdownNow;
public unsafe global::System.Collections.Generic.IList`1<global::Java.Lang.IRunnable> ShutdownNow ()
{
    if (id_shutdownNow == IntPtr.Zero)
        id_shutdownNow = JNIEnv.GetMethodID (class_ref, "shutdownNow", "()LSystem/Collections/Generic/IList`1;");
    return global::Java.Lang.Object.GetObject<global::System.Collections.Generic.IList`1> (JNIEnv.CallObjectMethod (Handle, id_shutdownNow), JniHandleOwnership.TransferLocalRef);
}

For some reason, the managed interface `IExecutorService` has this member:

[Register("shutdownNow", "()Ljava/util/List;", "GetShutdownNowHandler:Java.Util.Concurrent.IExecutorServiceInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
IList<IRunnable> ShutdownNow();

Why does my generated code have a nice ` in the middle?
Comment 1 Matthew Leibowitz 2016-05-19 21:15:55 UTC
Also noticed, that there was a class that implemented these interfaces, but generated this member wrong:

public virtual unsafe global::System.Collections.Generic.IList<global::Java.Lang.IRunnable> ShutdownNow ()

It should have been override. Onlky this was wrong, the others were implemented correctly
Comment 2 Matthew Leibowitz 2016-05-19 21:16:48 UTC
Version notes:

Microsoft Visual Studio Enterprise 2015
Version 14.0.25123.00 Update 2
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Enterprise

Architecture and Modeling Tools   00322-80000-00000-AA469
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2015   00322-80000-00000-AA469
Microsoft LightSwitch for Visual Studio 2015

Visual Basic 2015   00322-80000-00000-AA469
Microsoft Visual Basic 2015

Visual C# 2015   00322-80000-00000-AA469
Microsoft Visual C# 2015

Visual C++ 2015   00322-80000-00000-AA469
Microsoft Visual C++ 2015

Visual F# 2015   00322-80000-00000-AA469
Microsoft Visual F# 2015

Windows Phone SDK 8.0 - ENU   00322-80000-00000-AA469
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   5.206.60517.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015 (RC1 Update 1)   14.1.20203.0
ASP.NET and Web Tools 2015 (RC1 Update 1)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/

Azure App Service Tools v2.7.1   14.0.11112.0
Azure App Service Tools v2.7.1

Clang with Microsoft CodeGen   14.0.25115
Clang with Microsoft CodeGen

Common Azure Tools   1.7
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Devart Code Compare   4.1.78
Devart Code Compare
Copyright (c) 2012-2015 Devart. All rights reserved.
http://www.devart.com/codecompare/

GitHub.VisualStudio   1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JustDecompile Tools   1.0
Makes JustDecompile functionality available in VIsual Studio. Requires JustDecompile installation.

KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

MoveTypeToFile   1.0
MoveTypeToFile

NuGet Package Manager   3.4.3
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2015 ENU   14.0.23025
Microsoft Office Developer Tools for Visual Studio 2015 ENU

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

Python Tools for Visual Studio   2.2.40315.00
Python Tools for Visual Studio provides IntelliSense, projects, templates, Interactive windows, and other support for Python developers.

Python Tools for Visual Studio - Django Integration   2.2.40315.00
Provides templates and integration for the Django web framework.

Python Tools for Visual Studio - Profiling Support   2.2.40315.00
Profiling support for Python projects.

SQL Server Data Tools   14.0.60311.1
Microsoft SQL Server Data Tools

TypeScript   1.8.31.0
TypeScript tools for Visual Studio

Visual C++ for Cross Platform Mobile Development (Android)   14.0.25116.00
Visual C++ for Cross Platform Mobile Development (Android)

Visual C++ for Cross Platform Mobile Development (iOS)   14.0.25116.00
Visual C++ for Cross Platform Mobile Development (iOS)

Visual Studio Tools for Apache Cordova   Update 9
Visual Studio Tools for Apache Cordova

Visual Studio Tools for Universal Windows Apps   14.0.25208.00
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   4.1.0.496 (0026d9a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Inspector Support   0.8.1.0 (95792d1)
Adds support for inspecting Xamarin and WPF apps.

Xamarin.Android   6.1.0.56 (eabab32)
Visual Studio extension to enable development for Xamarin.Android.

Xamarin.iOS   9.8.0.317 (0611769)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 3 Atsushi Eno 2016-05-23 02:35:47 UTC
While the generated code in your project certainly contains some code that won't compile and had better be fixed, in general your use of non-generic Java classes derived from a generic Java class is a "not supported" use case.
https://developer.xamarin.com/guides/android/advanced_topics/limitations/ (particularly the last one)
Comment 4 Atsushi Eno 2016-08-17 06:47:57 UTC
As far as I can tell, the latest generator doesn't emit generic arguments IList`1 (at least anymore).

The assumption that binding methods always automatically override base C# methods is wrong; there are always possibility that a method in a class which is derived from some other class and implements some interfaces has conflict of interest between the base class method and the declaring interface method. They are always the same in C# but not in Java. For example below is a valid set of Java types:

public class Foo {}

public class Bar extends Foo {}

public class X
{
  public List<Foo> m () { ... }
}

public interface FeatureA
{
  List<Foo> m ();
}

public class Y extends X implements FeatureA
{
  public List<Bar> m () { ... } // the return types are different!!
}


You cannot do this in C#. You cannot assume that Y.M() should return IList<Foo> because that breaks IFeatureA C# interface.

Therefore you need metadata fixup.

(Marking RESOLVED as FIXED because we most likely had invalid code generation before.)