dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
201 stars 53 forks source link

Unable to parse generic types with generic type arguments #728

Closed thisisthekap closed 4 years ago

thisisthekap commented 4 years ago

Reproduction hosted at https://github.com/thisisthekap/repro-ArgumentOutOfRangeException.

I am not entirely sure if this is the right project to post this issue. Please just tell me if this one should be posted elsewhere (e.g. at https://github.com/xamarin/xamarin-android).

Repro steps:

git clone https://github.com/thisisthekap/repro-ArgumentOutOfRangeException.git
cd repro-ArgumentOutOfRangeException
msbuild /t:Restore
cd purchases-core-common
msbuild /t:Build -verbosity:diagnostic

The build fails, now search the build output for System.ArgumentOutOfRangeException.

Exception shown in build output:

  [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Length cannot be less than zero. (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000: [ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Length cannot be less than zero. [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
  Parameter name: length (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000: Parameter name: length [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at System.String.Substring (System.Int32 startIndex, System.Int32 length) [0x00031] in <3f2977eb306b45388f224fc6cc4db2c4>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at System.String.Substring (System.Int32 startIndex, System.Int32 length) [0x00031] in <3f2977eb306b45388f224fc6cc4db2c4>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x0009c] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x0009c] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x000ca] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x000ca] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x00117] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerationOptions.GetOutputName (System.String s) [0x00117] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerationOptions.GetTypeReferenceName (MonoDroid.Generation.ReturnValue symbol) [0x00007] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerationOptions.GetTypeReferenceName (MonoDroid.Generation.ReturnValue symbol) [0x00007] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerator.WriteProperty (MonoDroid.Generation.Property property, MonoDroid.Generation.GenBase gen, System.String indent, System.Boolean with_callbacks, System.Boolean force_override) [0x00340] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerator.WriteProperty (MonoDroid.Generation.Property property, MonoDroid.Generation.GenBase gen, System.String indent, System.Boolean with_callbacks, System.Boolean force_override) [0x00340] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerator.WriteImplementedProperties (System.Collections.Generic.IEnumerable`1[T] targetProperties, System.String indent, System.Boolean isFinal, MonoDroid.Generation.GenBase gen) [0x00079] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerator.WriteImplementedProperties (System.Collections.Generic.IEnumerable`1[T] targetProperties, System.String indent, System.Boolean isFinal, MonoDroid.Generation.GenBase gen) [0x00079] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.CodeGenerator.WriteClass (MonoDroid.Generation.ClassGen class, System.String indent, MonoDroid.Generation.GenerationInfo gen_info) [0x004fa] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.CodeGenerator.WriteClass (MonoDroid.Generation.ClassGen class, System.String indent, MonoDroid.Generation.GenerationInfo gen_info) [0x004fa] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at MonoDroid.Generation.ClassGen.Generate (MonoDroid.Generation.CodeGenerationOptions opt, MonoDroid.Generation.GenerationInfo gen_info) [0x0007d] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at MonoDroid.Generation.ClassGen.Generate (MonoDroid.Generation.CodeGenerationOptions opt, MonoDroid.Generation.GenerationInfo gen_info) [0x0007d] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options, Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x005b6] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options, Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x005b6] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options) [0x0001b] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at Xamarin.Android.Binder.CodeGenerator.Run (Xamarin.Android.Binder.CodeGeneratorOptions options) [0x0001b] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
    at Xamarin.Android.Binder.CodeGenerator.Main (System.String[] args) [0x0000c] in <598b9b8c977642d18bee713c178d3b71>:0  (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): message BG0000:   at Xamarin.Android.Binder.CodeGenerator.Main (System.String[] args) [0x0000c] in <598b9b8c977642d18bee713c178d3b71>:0  [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj] (TaskId:177)
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Bindings.targets(372,5): error MSB6006: "generator.exe" exited with code 1. [/thepath/repro-ArgumentOutOfRangeException/purchases-core-common/purchases-core-common.csproj]
jpobst commented 4 years ago

It looks like we are throwing the exception trying to parse generic types with generic types:

System.Collections.Generic.IDictionary<System.Collections.Generic.IList<string>, System.Collections.Generic.IList<Kotlin.Pair>>

I will work on fixing our parser to support this.

The only workaround I can think of is to remove the methods that are trying to use this type:

<remove-node path="/api/package[@name='com.revenuecat.purchases.common']/class[@name='Backend']/method[@name='getCallbacks']" />
<remove-node path="/api/package[@name='com.revenuecat.purchases.common']/class[@name='Backend']/method[@name='setCallbacks']" />
<remove-node path="/api/package[@name='com.revenuecat.purchases.common']/class[@name='Backend']/method[@name='getPostReceiptCallbacks']" />
<remove-node path="/api/package[@name='com.revenuecat.purchases.common']/class[@name='Backend']/method[@name='setPostReceiptCallbacks']" />
thisisthekap commented 4 years ago

@jpobst Thank you very much for the fast analysis!

Can you already provide a rough estimate when this issue is going to be fixed?