Skip to content

Commit 69767c1

Browse files
authored
[param-name-importer] Fix NSE when updating JavaApi.AllPackages (#807)
In commit 0cb8e2d, we switched from using `List<JavaPackage>` to `Dictionary<string, JavaPackage>` for better performance. To minimize the diffs needed with existing code, we created an accessor for `Dictionary<string, JavaPackage>.Values`: partial class JavaApi { public IDictionary<string, JavaPackage> Packages { get; } public ICollection<JavaPackage> AllPackages => Packages.Values; } However, if you attempt to modify this collection directly -- as is done by `tools/param-name-importer` -- you get an exception:` System.NotSupportedException: Mutating a value collection derived from a dictionary is not allowed. at System.ThrowHelper.ThrowNotSupportedException(ExceptionResource resource) at Xamarin.Android.ApiTools.JavaStubImporter.JavaStubSourceImporter.ParseJava(String javaSourceText) in …\Java.Interop\tools\param-name-importer\JavaStubSourceImporter.cs:line 81 at Xamarin.Android.ApiTools.JavaStubImporter.JavaStubSourceImporter.Import(ImporterOptions options) in …\Java.Interop\tools\param-name-importer\JavaStubSourceImporter.cs:line 27 at Xamarin.Android.ApiTools.Driver.Main(String[] args) in …\Java.Interop\tools\param-name-importer\Program.cs:line 22 Update `tools/param-name-importer` to use `api.Packages.Add()` instead of `api.AllPackages.Add()` to avoid the exception. Verified that this is the only code that attempts to modify `JavaApi.AllPackages`.
1 parent a666a6f commit 69767c1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/param-name-importer/JavaStubSourceImporter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bool ParseJava (string javaSourceText)
7878
}
7979
var pkg = api.AllPackages.FirstOrDefault (p => p.Name == parsedPackage.Name);
8080
if (pkg == null) {
81-
api.AllPackages.Add (parsedPackage);
81+
api.Packages.Add (parsedPackage.Name, parsedPackage);
8282
pkg = parsedPackage;
8383
} else
8484
foreach (var t in parsedPackage.AllTypes)

0 commit comments

Comments
 (0)