Skip to content

[param-name-importer] Fix crash trying to modify a Dictionary.Values collection directly #807

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

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Feb 23, 2021

In #756, 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 the Dictionary.Values:

public IDictionary<string, JavaPackage>Packages { get; }
public ICollection<JavaPackage> AllPackages => Packages.Values;

However if you attempt to modify this collection directly, 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 C:\code\xamarin-android-backport\external\Java.Interop\tools\param-name-importer\JavaStubSourceImporter.cs:line 81
   at Xamarin.Android.ApiTools.JavaStubImporter.JavaStubSourceImporter.Import(ImporterOptions options) in C:\code\xamarin-android-backport\external\Java.Interop\tools\param-name-importer\JavaStubSourceImporter.cs:line 27
   at Xamarin.Android.ApiTools.Driver.Main(String[] args) in C:\code\xamarin-android-backport\external\Java.Interop\tools\param-name-importer\Program.cs:line 22

Thus we need to update this code that adds to the collection to use the dictionary properly.

Also verified that this is the only code that attempts to write to AllPackages.

@jpobst jpobst changed the title [param-name-importer] Fix crash trying to modify a Dictionary.Values directly [param-name-importer] Fix crash trying to modify a Dictionary.Values collection directly Feb 23, 2021
@jonpryor jonpryor merged commit 69767c1 into main Feb 23, 2021
@jonpryor jonpryor deleted the param-dictionary branch February 23, 2021 21:01
@jpobst jpobst added this to the 11.3 (16.10 / 8.10) milestone Mar 1, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 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.

2 participants