Fix GridView.Adapter CA1416 false positive#12109
Merged
Merged
Conversation
Match removed property accessors against supported Java base methods, including generic setter specializations. Restore the analyzer regression cases and add GridView.Adapter coverage for #12107. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5ee5ebf9-0580-4cab-916a-a702e18c5dc3
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the in-tree Java.Interop generator override/fixup logic to prevent a CA1416 false-positive on Android.Widget.GridView.Adapter.set by recognizing when a “removed” property accessor is actually satisfied by a supported base-class Java method (including generic-specialization cases). It also adds regression coverage in both generator unit tests and an end-to-end BuildHasNoWarnings build test.
Changes:
- Update
GenBase.FixupMethodOverrides()to clearApiRemovedSinceon property accessors when a matching supported base Java method exists (including a special-case for setters overriding a generic base setter parameter). - Add a Java.Interop generator regression test for
GridView.Adapter. - Add an Android build regression snippet to ensure no warnings for
FrameLayout.Foreground,GridView.Adapter,ListView.Adapter, andMediaStore.*.DateTaken.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs | Adds end-to-end “no warnings” regression usage for the affected APIs, including GridView.Adapter setter. |
| external/Java.Interop/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs | Adjusts accessor-vs-base-method matching for ApiRemovedSince fixup to avoid false “unsupported” annotations. |
| external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs | Adds a generator regression test intended to cover the GridView.Adapter scenario. |
simonrozsival
approved these changes
Jul 15, 2026
Restrict specialized setter matching to generic type parameters so concrete generic overloads do not suppress valid platform attributes. Add focused positive and negative property-accessor regression tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5ee5ebf9-0580-4cab-916a-a702e18c5dc3
simonrozsival
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GridView.AdapterFrameLayout.Foreground,ListView.Adapter, andMediaStore.DateTakenContext
This finishes the regression coverage and generator work started in:
UnsupportedOSPlatformfor property setters when base has getter-only java-interop#1374The relevant history is:
[UnsupportedOSPlatform]if it overrides a supported base method. java-interop#1313 introduced suppression of[UnsupportedOSPlatform]on supported overrides.FixupMethodOverrides()checks properties java-interop#1366 extended that handling to properties.[UnsupportedOSPlatform]java-interop#1367 reverted the platform-attribute changes fromrelease/10.0.1xxto reduce risk for .NET 10: dotnet/java-interop@0ad0d40main, where the genericGridView.Adaptersetter case was investigated in the unfinished Java.Interop PR above but left unresolved.Java.Interop is now integrated into this repository, so this applies the focused generator fix directly in-tree.
Testing
IsGenericmatchBuildHasNoWarningsmatrix passes, with the three unsupported Debug NativeAOT cases skippedFixes: #12107