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

[Xamarin.Android.Build.Tasks] fix NRE in XAJavaTypeScanner #9087

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

jonathanpeppers
Copy link
Member

Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9842772&view=logs&j=9a1c0345-5071-55ee-c0f3-a2911782c698&t=1e33272b-48f7-5132-3788-3179300312b4

We saw an NRE in XAJavaTypeScanner in the build linked above:

Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001: System.NullReferenceException: Object reference not set to an instance of an object.
Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.XAJavaTypeScanner.GetJavaTypes(ICollection`1 inputAssemblies, XAAssemblyResolver resolver)
Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(XAAssemblyResolver res, Boolean useMarshalMethods)
Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

I set #nullable enable in this file, and fixed the one warning that exists.

Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9842772&view=logs&j=9a1c0345-5071-55ee-c0f3-a2911782c698&t=1e33272b-48f7-5132-3788-3179300312b4

We saw an NRE in `XAJavaTypeScanner` in the build linked above:

    Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001: System.NullReferenceException: Object reference not set to an instance of an object.
    Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.XAJavaTypeScanner.GetJavaTypes(ICollection`1 inputAssemblies, XAAssemblyResolver resolver)
    Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(XAAssemblyResolver res, Boolean useMarshalMethods)
    Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
    Microsoft.Android.Sdk.Darwin/34.0.95/tools/Xamarin.Android.Common.targets(1536,3): error XAGJS7001:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

I set `#nullable enable` in this file, and fixed the one warning that
exists.
AssemblyDefinition asmdef = resolver.Load (asmItem.ItemSpec);
AssemblyDefinition? asmdef = resolver.Load (asmItem.ItemSpec);
if (asmdef == null)
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice if it logged a warning here. This is not a normal situation, and skipping an assembly might lead to "mysterious" errors later on, if that assembly happens to have JLO types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put LogDebugMessage(), as a warning would not be actionable. There wouldn't be a good way for a developer to fix the warning.

@jonpryor jonpryor merged commit 2b5392a into dotnet:main Jul 8, 2024
57 checks passed
@jonathanpeppers jonathanpeppers deleted the XAJavaTypeScannerNRE branch July 8, 2024 20:19
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 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.

4 participants