Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] fix NRE in XAJavaTypeScanner (#9087)
Browse files Browse the repository at this point in the history
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 a `NullReferenceException` 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 added `#nullable enable` to `XAJavaTypeScanner.cs`, and fixed the
one warning that existed around `resolver.Load()`.  Now, when
`resolver.Load()` returns `null`, we'll log the Debug message:

	[{targetArch}] Unable to load assembly '…'
  • Loading branch information
jonathanpeppers authored Jul 8, 2024
1 parent 6b665dc commit 2b5392a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -48,7 +49,11 @@ public List<TypeDefinition> GetJavaTypes (ICollection<ITaskItem> inputAssemblies
throw new InvalidOperationException ($"Internal error: assembly '{asmItem.ItemSpec}' should be in the '{targetArch}' architecture, but is in '{arch}' instead.");
}

AssemblyDefinition asmdef = resolver.Load (asmItem.ItemSpec);
AssemblyDefinition? asmdef = resolver.Load (asmItem.ItemSpec);
if (asmdef == null) {
log.LogDebugMessage ($"[{targetArch}] Unable to load assembly '{asmItem.ItemSpec}'");
continue;
}

foreach (ModuleDefinition md in asmdef.Modules) {
foreach (TypeDefinition td in md.Types) {
Expand Down

0 comments on commit 2b5392a

Please sign in to comment.