Skip to content

[Java.Interop] Fix inherited JCW interfaces - #12333

Merged
jonathanpeppers merged 3 commits into
dotnet:mainfrom
jonathanpeppers:jonathanpeppers-fix-tablayout-listener2
Aug 11, 2026
Merged

[Java.Interop] Fix inherited JCW interfaces#12333
jonathanpeppers merged 3 commits into
dotnet:mainfrom
jonathanpeppers:jonathanpeppers-fix-tablayout-listener2

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Fixes #11917.

Java callable wrapper generation now omits registered interfaces already inherited through a more-derived registered interface. This prevents generated Java classes from implementing both TabLayout.OnTabSelectedListener and its raw generic BaseOnTabSelectedListener, which javac rejects.

Adds:

  • a focused JCW generator regression test for retaining only the most-derived interface
  • an MSBuildDeviceIntegration test that builds and launches an app implementing TabLayout.IOnTabSelectedListener2, selects a tab, and verifies OnTabSelected runs

Validation:

  • Java.Interop.Tools.JavaCallableWrappers-Tests: 48 passed
  • Device integration compile/run not completed locally: current main targets .NET 11, while this machine has a .NET 10 SDK, and no Android device was connected

Only emit the most-derived registered interfaces in Java callable wrappers and cover TabLayout listener generation with unit and device integration tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 92a1a03f-a5e0-4475-96fd-adb6cd5d193c
Copilot AI lite review requested due to automatic review settings August 10, 2026 16:30

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

Updates the Java Callable Wrapper (JCW) generator in Java.Interop to avoid emitting redundant inherited registered interfaces, preventing invalid Java implements lists that javac rejects (e.g., TabLayout.OnTabSelectedListener vs its base listener type). Adds both a focused generator regression test and a device integration test to validate the scenario end-to-end.

Changes:

  • Update JCW interface collection to omit registered interfaces that are already inherited through a more-derived registered interface.
  • Add a JavaCallableWrappers unit/regression test ensuring only the most-derived registered interface is emitted.
  • Add an MSBuildDeviceIntegration test app that implements TabLayout.IOnTabSelectedListener2 and verifies OnTabSelected runs on launch.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs Adds device integration coverage for TabLayout.IOnTabSelectedListener2 execution via logcat assertion.
external/Java.Interop/tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers/SupportDeclarations.cs Adds minimal registered base/derived interface declarations used by the regression test.
external/Java.Interop/tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGeneratorTests.cs Adds regression test asserting the generated wrapper keeps only the most-derived registered interface.
external/Java.Interop/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.Adapters/CecilImporter.cs Implements the interface filtering/deduplication logic in the Cecil-based importer used by the generator.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Avoid interpolation in the generated MainActivity source so the expected logcat marker is explicit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 92a1a03f-a5e0-4475-96fd-adb6cd5d193c
Use a MaterialComponents theme so TabLayout can be constructed and the listener callback can run during the device integration test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 92a1a03f-a5e0-4475-96fd-adb6cd5d193c
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer failed. Please review the logs for details.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Aug 11, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the current changes. Interface selection removes redundant registered bases while preserving independent interfaces and deterministic order; Java-name deduplication handles erasure, callback collection is unchanged, and focused plus on-device tests pass. No blocking issues found.

@jonathanpeppers
jonathanpeppers merged commit 417ccbe into dotnet:main Aug 11, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use TabLayout.IOnTabSelectedListener2

3 participants