Skip to content

Fix GridView.Adapter CA1416 false positive#12109

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-fix-gridview-analyzer
Jul 15, 2026
Merged

Fix GridView.Adapter CA1416 false positive#12109
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-fix-gridview-analyzer

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary

  • match removed property accessors against supported Java base methods
  • handle setters that specialize generic base setter type parameters without matching unrelated concrete generic types
  • add focused positive and negative generator regression coverage
  • add end-to-end analyzer regression coverage for GridView.Adapter
  • preserve the existing regression cases for FrameLayout.Foreground, ListView.Adapter, and MediaStore.DateTaken

Context

This finishes the regression coverage and generator work started in:

The relevant history is:

Java.Interop is now integrated into this repository, so this applies the focused generator fix directly in-tree.

Testing

  • all 466 Java.Interop generator tests pass
  • positive mutation checks fail when the accessor fix is disabled
  • the concrete-generic guard fails with the previous broad IsGeneric match
  • the 10-case Android BuildHasNoWarnings matrix passes, with the three unsupported Debug NativeAOT cases skipped

Fixes: #12107

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
Copilot AI review requested due to automatic review settings July 14, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clear ApiRemovedSince on 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, and MediaStore.*.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.

Comment thread external/Java.Interop/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs Outdated
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
@jonathanpeppers
jonathanpeppers merged commit df45a7d into main Jul 15, 2026
44 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-fix-gridview-analyzer branch July 15, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CA1416 false positive: Android.Widget.GridView.Adapter.set

3 participants