Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generator] Fix an NRE when cloning a method with generic arguments. #1089

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Mar 30, 2023

Context: #1080

When running the latest generator against GooglePlayServices, it hits an NRE when attempting to Method.Clone (...) a method with generic arguments while building com.google.firebase.firebase-components.csproj:

BINDINGSGENERATOR error BG0000: System.NullReferenceException: Object reference not set to an instance of an object. [c:\g\generated\com.google.firebase.firebase-components\com.google.firebase.firebase-components.csproj]
error BG0000: System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoDroid.Generation.Method.Clone(GenBase declaringType) in C:\code\xamarin-android\external\Java.Interop\tools\generator\Java.Interop.Tools.Generator.ObjectModel\Method.cs:line 131
   at MonoDroid.Generation.Method.Clone(GenBase declaringType) in C:\code\xamarin-android\external\Java.Interop\tools\generator\Java.Interop.Tools.Generator.ObjectModel\Method.cs:line 131
   at MonoDroid.Generation.ClassGen.FixupAccessModifiers(CodeGenerationOptions opt) in C:\code\xamarin-android\external\Java.Interop\tools\generator\Java.Interop.Tools.Generator.ObjectModel\ClassGen.cs:line 67
   at MonoDroid.Generation.ClassGen.FixupAccessModifiers(CodeGenerationOptions opt) in C:\code\xamarin-android\external\Java.Interop\tools\generator\Java.Interop.Tools.Generator.ObjectModel\ClassGen.cs:line 67
   at Xamarin.Android.Binder.CodeGenerator.Validate(List`1 gens, CodeGenerationOptions opt, CodeGeneratorContext context) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 300
   at Xamarin.Android.Binder.CodeGenerator.Validate(List`1 gens, CodeGenerationOptions opt, CodeGeneratorContext context) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 300
   at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options, DirectoryAssemblyResolver resolver) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 208
   at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options, DirectoryAssemblyResolver resolver) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 208
   at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 50
   at Xamarin.Android.Binder.CodeGenerator.Run(CodeGeneratorOptions options) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 50
   at Xamarin.Android.Binder.CodeGenerator.Main(String[] args) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 33
   at Xamarin.Android.Binder.CodeGenerator.Main(String[] args) in C:\code\xamarin-android\external\Java.Interop\tools\generator\CodeGenerator.cs:line 33

This is because the MethodBase.GenericArguments collection is null unless it has items. Thus we need to create it before populating it with items.

@jpobst jpobst marked this pull request as ready for review March 30, 2023 15:06
@jonpryor jonpryor merged commit 8f3fe62 into main Mar 30, 2023
@jonpryor jonpryor deleted the clone-nre branch March 30, 2023 15:26
jonpryor pushed a commit to dotnet/android that referenced this pull request Mar 31, 2023
Fixes: dotnet/java-interop#1090

Changes: dotnet/java-interop@53bfb4a...0355acf

  * dotnet/java-interop@0355acf8: [Xamarin.Android.Tools.Bytecode] Ignore synthetic ctor params (dotnet/java-interop#1091)
  * dotnet/java-interop@909239d4: [generator] Add support for peerConstructorPartialMethod (dotnet/java-interop#1087)
  * dotnet/java-interop@8f3fe625: [generator] Fix an NRE when cloning a method with generic arguments (dotnet/java-interop#1089)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants