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

[jnimarshalmethod-gen] Fix type resolution crash #706

Merged

Conversation

radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented Sep 3, 2020

The TypeMover was crashing, when we cannot resolve the type during
register method optimization.

Like this:

Value cannot be null.
Parameter name: key
System.ArgumentNullException: Value cannot be null.
Parameter name: key
  at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) [0x00175] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/debug/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:470
  at System.Collections.Generic.Dictionary`2[TKey,TValue].ContainsKey (TKey key) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/debug/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:286
  at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.Resolve (Mono.Cecil.TypeReference type) [0x00001] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:143
  at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.GetActionConstructor (Mono.Cecil.TypeReference type, Mono.Cecil.ModuleDefinition module) [0x00012] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:335
  at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.AnalyzeAndImprove (Mono.Collections.Generic.Collection`1[T] instructions, Mono.Collections.Generic.Collection`1[T] newInstructions, System.Int32 idx, System.String typeName, System.Int32& skipCount, Mono.Cecil.ModuleDefinition module) [0x003b6] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:417

The tool was crashing on IL like this:

IL_0122:  ldstr      "Delegate18$1"
IL_0127:  ldc.i4.1
IL_0128:  call       [mscorlib]System.Type [mscorlib]System.Type::GetType(string,
                                                                          bool)

The fix makes us more error resistant. It doesn't fix the source of the problem,
which will be fixed elsewhere.

More information about the issue which led to the crash: #709

The TypeMover was crashing, when we cannot resolve the type during
register method optimization.

Like this:

    Value cannot be null.
    Parameter name: key
    System.ArgumentNullException: Value cannot be null.
    Parameter name: key
      at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) [0x00175] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/debug/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:470
      at System.Collections.Generic.Dictionary`2[TKey,TValue].ContainsKey (TKey key) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/debug/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:286
      at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.Resolve (Mono.Cecil.TypeReference type) [0x00001] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:143
      at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.GetActionConstructor (Mono.Cecil.TypeReference type, Mono.Cecil.ModuleDefinition module) [0x00012] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:335
      at Xamarin.Android.Tools.JniMarshalMethodGenerator.TypeMover.AnalyzeAndImprove (Mono.Collections.Generic.Collection`1[T] instructions, Mono.Collections.Generic.Collection`1[T] newInstructions, System.Int32 idx, System.String typeName, System.Int32& skipCount, Mono.Cecil.ModuleDefinition module) [0x003b6] in /Users/rodo/git/xa-clean/external/Java.Interop/tools/jnimarshalmethod-gen/TypeMover.cs:417

The tool was crashing on IL like this:

    IL_0122:  ldstr      "Delegate18$1"
    IL_0127:  ldc.i4.1
    IL_0128:  call       [mscorlib]System.Type [mscorlib]System.Type::GetType(string,
                                                                              bool)

The fix makes us more error prone. It doesn't fix the source of the problem,
which will be fixed elsewhere.
@radekdoulik
Copy link
Member Author

Context: the issue which leads to and exposes the crash is being fixed in #711

@radekdoulik radekdoulik merged commit 03c2272 into dotnet:master Sep 8, 2020
@jpobst jpobst added this to the 11.1 (16.9 / 8.9) milestone Sep 22, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 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