Skip to content

[typemap] Reject duplicate generated JCW names - #12569

Open
simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-duplicate-jcw-names
Open

[typemap] Reject duplicate generated JCW names#12569
simonrozsival wants to merge 2 commits into
mainfrom
simonrozsival-duplicate-jcw-names

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • capture llvm-ir XA4214/XA4215 behavior with cross-assembly duplicate Java wrapper fixtures
  • reject conflicting generated JCW names before writing typemap, Java, or ACW-map outputs
  • emit existing localized XA4215 header/detail diagnostics deterministically
  • preserve intentional alias groups and legacy same-module behavior

TDD evidence

Before the fix, the unchanged fixture failed with XA4215 under llvm-ir but succeeded under trimmable CoreCLR and NativeAOT. Trimmable wrote duplicate ACW-map entries, overwrote one DuplicatePeer.java, and retained inconsistent mappings.

After the fix, the focused llvm-ir, trimmable CoreCLR, and trimmable NativeAOT fixture passes 3/3. Additional validation:

  • standalone trimmable typemap suite: 771/771
  • GenerateTrimmableTypeMap task tests: 14/14

Part of #12561

simonrozsival and others added 2 commits August 28, 2026 14:41
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

Review tier: Lite
Findings: 2 Low severity

New issues introduced by this change (2)
Severity Finding
Low severity src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​BuildWithLibraryTests.cs — 💡 suggestionerrors is never null because Where(...) returns a non-null enumerable.…
Low severity tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapGeneratorTests.cs — 💡 suggestion — The new XA4215 regression test uses broad Contains predicates, which can…
What changed in this PR

This PR closes a feature-parity gap in the trimmable typemap pipeline by detecting cross-assembly collisions in generated Java wrapper (JCW) names early and emitting deterministic, localized XA4215 diagnostics, preventing ambiguous Java/acw-map/typemap outputs.

Changes:

  • Add duplicate generated Java type validation in TrimmableTypeMapGenerator.ValidateJavaNames() and log XA4215 header + detail lines deterministically.
  • Extend the trimmable typemap logger interface and MSBuild task logger to emit XA4215 diagnostics via localized resource strings.
  • Add/expand regression coverage for duplicate generated JCW names across llvm-ir, trimmable CoreCLR, and trimmable NativeAOT builds.
File Description
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapGeneratorTests.cs Adds a focused unit test asserting XA4215 emission for duplicate generated JCW names.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​BuildWithLibraryTests.cs Expands integration coverage to validate XA4215 behavior and output artifacts across typemap implementations/runtimes.
src/​Xamarin.Android.Build.Tasks/​Tasks/​GenerateTrimmableTypeMap.cs Implements new XA4215 logging methods in the MSBuild logger using localized resources.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​TrimmableTypeMapGenerator.cs Adds early cross-assembly duplicate JCW name rejection with deterministic XA4215 logging.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​ITrimmableTypeMapLogger.cs Extends the logging interface with XA4215 header/detail methods.

Comment on lines 694 to 695
IEnumerable<string> errors = appb.LastBuildOutput.Where (x => x.Contains ("error XA4215"));
Assert.NotNull (errors, "Error should be XA4215");
Comment on lines +127 to +131
Assert.False (CreateGenerator ().ValidateJavaNames (peers));
Assert.Contains (logMessages, message => message.Contains ("XA4215") && message.Contains ("examplelib.DuplicatePeer"));
Assert.Contains (logMessages, message => message.Contains ("Library1.FirstPeer, Library1"));
Assert.Contains (logMessages, message => message.Contains ("Library2.SecondPeer, Library2"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants