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

Address breaking changes in Java.Interop #7664

Merged
merged 2 commits into from Jan 9, 2023

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Jan 4, 2023

Context: xamarin/java.interop#1069

Any place we had:

TypeDefinitionCache?
IMetadataResolver?

These no longer allow nulls, and so overloads that use Obsolete now emit errors instead of warnings:

[Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)]
public static MethodDefinition GetBaseDefinition (this MethodDefinition method) => throw new NotSupportedException ();

This results in 3 compiler errors in xamarin-android:

src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(65,11): error CS0619: 'TypeDefinitionRocks.IsSubclassOf(TypeDefinition, string)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(268,12): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
src\Xamarin.Android.Build.Tasks\Utilities\ManifestDocumentElement.cs(28,11): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'

After these changes, it appears we will improve the performance further of apps that use:

  • ApplicationAttribute.BackupAgent
  • ApplicationAttribute.Name
  • AndroidManifest.xml attributes that take a System.Type values

Context: xamarin/java.interop#1069

Any place we had:

    TypeDefinitionCache?
    IMetadataResolver?

These no longer allow nulls, and so overloads that use `Obsolete` now
emit errors instead of warnings:

    [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)]
    public static MethodDefinition GetBaseDefinition (this MethodDefinition method) =>
        GetBaseDefinition (method, resolver: null!);

This results in 3 compiler errors in xamarin-android:

    src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(65,11): error CS0619: 'TypeDefinitionRocks.IsSubclassOf(TypeDefinition, string)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
    src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(268,12): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'
    src\Xamarin.Android.Build.Tasks\Utilities\ManifestDocumentElement.cs(28,11): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.'

After these changes, it appears we will improve the performance
further of apps that use:

* `ApplicationAttribute.BackupAgent`
* `ApplicationAttribute.Name`
* `AndroidManifest.xml` attributes that take a `System.Type` values

Additionally, fix NRE in the linker:

    Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetBaseType(TypeDefinition type, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 21
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.GetTypeAndBaseTypes(TypeDefinition type, IMetadataResolver resolver)+MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 36
    at Java.Interop.Tools.Cecil.TypeDefinitionRocks.IsSubclassOf(TypeDefinition type, String typeName, IMetadataResolver resolver) in /Users/builder/azdo/_work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs:line 87
    at MonoDroid.Tuner.FixAbstractMethodsStep.ProcessType(TypeDefinition type) in /Users/builder/azdo/_work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/FixAbstractMethodsStep.cs:line 81
    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, Nullable`1 origin)
    at Mono.Linker.Steps.MarkStep.MarkField(FieldDefinition field, DependencyInfo& reason, MessageOrigin& origin)
    at Mono.Linker.Steps.MarkStep.MarkEntireType(TypeDefinition type, DependencyInfo& reason)
    at Mono.Linker.Steps.MarkStep.MarkEntireAssembly(AssemblyDefinition assembly)
    at Mono.Linker.Steps.MarkStep.MarkAssembly(AssemblyDefinition assembly, DependencyInfo reason)
    at Mono.Linker.Steps.MarkStep.MarkModule(ModuleDefinition module, DependencyInfo reason)
    at Mono.Linker.Steps.MarkStep.ProcessMarkedPending()
    at Mono.Linker.Steps.MarkStep.Initialize()
    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
    at Mono.Linker.Pipeline.Process(LinkContext context)
    at Mono.Linker.Driver.Run(ILogger customLogger)
    at Mono.Linker.Driver.Main(String[] args)

This was caused by removing null checks in Java.Interop.
Bumps [external/Java.Interop](https://github.com/xamarin/java.interop) from `f8d77fa` to `cf80deb`.
- [Release notes](https://github.com/xamarin/java.interop/releases)
- [Commits](xamarin/java.interop@f8d77fa...cf80deb)

---
updated-dependencies:
- dependency-name: external/Java.Interop
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
@jonathanpeppers jonathanpeppers marked this pull request as ready for review January 9, 2023 14:43
@jonpryor jonpryor merged commit 59e7adc into xamarin:main Jan 9, 2023
@jonathanpeppers jonathanpeppers deleted the JavaInteropBreakingChanges branch January 9, 2023 18:50
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 17, 2023
* main:
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (xamarin#7680)
  [ci] Move OneLocBuild task to scheduled pipeline (xamarin#7679)
  [Mono.Android] ServerCertificateValidationCallback() and redirects (xamarin#7662)
  Bump to xamarin/java.interop@cf80deb7 (xamarin#7664)
  Localized file check-in by OneLocBuild (xamarin#7668)
  [api-merge] Correctly compute //method/@deprecated-since (xamarin#7645)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer (xamarin#6427)
  [Xamarin.Android.Build.Tasks] downgrade d8/r8 `warning` messages to `info` (xamarin#7643)
  [Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (xamarin#7642)
  [Xamarin.Android.Build.Tasks] delay ToJniName calls in ManifestDocument (xamarin#7653)
  [Xamarin.Android.Build.Tasks] fast path for `<CheckClientHandlerType/>` (xamarin#7652)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 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.

None yet

2 participants