Skip to content

Commit 2b5392a

Browse files
[Xamarin.Android.Build.Tasks] fix NRE in XAJavaTypeScanner (#9087)
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 '…'
1 parent 6b665dc commit 2b5392a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Xamarin.Android.Build.Tasks/Utilities/XAJavaTypeScanner.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#nullable enable
12
using System;
23
using System.Collections.Generic;
34
using System.IO;
@@ -48,7 +49,11 @@ public List<TypeDefinition> GetJavaTypes (ICollection<ITaskItem> inputAssemblies
4849
throw new InvalidOperationException ($"Internal error: assembly '{asmItem.ItemSpec}' should be in the '{targetArch}' architecture, but is in '{arch}' instead.");
4950
}
5051

51-
AssemblyDefinition asmdef = resolver.Load (asmItem.ItemSpec);
52+
AssemblyDefinition? asmdef = resolver.Load (asmItem.ItemSpec);
53+
if (asmdef == null) {
54+
log.LogDebugMessage ($"[{targetArch}] Unable to load assembly '{asmItem.ItemSpec}'");
55+
continue;
56+
}
5257

5358
foreach (ModuleDefinition md in asmdef.Modules) {
5459
foreach (TypeDefinition td in md.Types) {

0 commit comments

Comments
 (0)