Skip to content

[release/11.0.1xx][TrimmableTypeMap] Validate generated top-level Java identifiers - #13405

Merged
jonathanpeppers merged 2 commits into
release/11.0.1xxfrom
simonrozsival-backport-jni-name-validation
Nov 10, 2026
Merged

jonathanpeppers merged 2 commits into
release/11.0.1xxfrom
simonrozsival-backport-jni-name-validation

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Backport #13311 (536fa66) to release/11.0.1xx.

Context: #13147
Context: #13306 (comment)

The release branch already contains #13306, but validation still splits generated top-level Java identifiers at $. Valid component names such as example.components.Outer$for therefore fail with XA4258 when referenced in constructor/export signatures or deferred registration.

Preserve generated identifiers as a whole while continuing to validate package segments and external Java nested-type identifiers. Include the upstream README update, all 58 focused regression cases, and the expanded application-build matrix covering six component attributes, both CoreCLR and NativeAOT, same- and cross-assembly references, and three identifier forms.

The release branch retains the separate xUnit typemap test project rather than main's consolidated NUnit test layout. A follow-up commit moves and adapts the 58 cases to that existing project, reuses its logger/internal access, and updates three obsolete deferred-registration expectations. No unrelated return-only regression cases are included.

Commits:

  • 84343db — upstream cherry-pick with -x attribution.
  • 7d3023b — release-specific test compatibility.

Local validation

  • make prepare — passed.
  • make leeroy — passed; builds the SDK, extra stable API levels, and local workload. Used instead of make all because this release builds API levels 37, 37.1, and 37.2.
  • dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal --filter 'FullyQualifiedName~TrimmableTypeMapJavaNameTests' — passed: 58, failed: 0, skipped: 0.
  • dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj -v minimal --no-restore — passed: 1,074, failed: 0, skipped: 0.
  • dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --no-restore — passed: 17, failed: 0, skipped: 7 SDK-dependent tests; this run preceded local SDK preparation.

App-build command (session-specific output directory and shell log redirection omitted):

./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~Build_ComponentNameIsUsedInSignatures|Name~Build_InvalidOrUnsupportedUnicodeIdentifiers_ReportDiagnosticWithoutTrimmableOutputs|Name~Build_IndependentConstructorAndJavaNameDiagnostics_AreBothReported|Name~Build_CanonicallyEquivalentJavaNames_DoNotOverwriteOutputs' --logger 'trx;LogFileName=backport-java-name.trx'

Passed: 81, failed: 0, skipped: 0, in 27m 27s. Includes all 72 expanded component-signature cases and 9 related invalid-name/diagnostic cases, with generated Java and packaged DEX assertions. No pending SDK/app-build validation or preparation/build blockers remain.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

simonrozsival and others added 2 commits November 5, 2026 13:27
)

Context: #13147
Context: #13306 (comment)

An explicit component name such as `example.components.Outer$for` is a valid top-level Java identifier, but constructor and export signatures referencing it fail with XA4258.  Application and Instrumentation wrappers with these names also fail deferred-registration validation, even without a signature referencing them.

The source generator preserves `$` in generated wrapper names after #13147, but validation still splits every source reference at `$` and rejects the resulting keyword `for`.  Pass the generated-peer name set through source-type and JNI descriptor validation so validation uses the same top-level-versus-nested distinction as source generation.  Continue checking package segments and the complete generated identifier, and retain nested-identifier validation for external Java types.

Add 58 focused regression cases covering generated and external references, invalid identifiers, deferred registration, and default-package throws clauses.  Extend the existing application-build matrix with `Outer$for`, retaining its generated-source and packaged-DEX assertions for all six component attributes, both runtimes, and same- and cross-assembly references.

(cherry picked from commit 536fa66)

Co-authored-by: Copilot App <[email protected]>
Keep all 58 upstream regression cases in the release branch typemap test assembly, reuse its logger and internal access, and update legacy deferred-registration expectations for generated top-level identifiers.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 13:16

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.

🟢 Approval recommended

No active review issues remain for the generated Java name validation backport.

No open issues 🎉

What changed in this PR

Backports generated Java name validation to release/11.0.1xx, completing the earlier component-name fix. Generated wrappers such as Outer$for retain their full identifier, while external nested Java types continue to validate each nested identifier.

Changes:

  • Pass generated-peer names through source-reference, JNI descriptor, and deferred-registration validation.
  • Add 58 focused xUnit regression cases and update obsolete deferred-registration expectations.
  • Expand the application-build matrix to 72 cases across six component attributes, two runtimes, and same- and cross-assembly references.
File Description
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapJavaNameTests.cs Adds 58 generated-versus-external name regression cases.
tests/​Microsoft.Android.Sdk.TrimmableTypeMap.Tests/​Generator/​TrimmableTypeMapGeneratorTests.cs Updates deferred-registration validation expectations.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds Outer$for to the component-signature build matrix.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​TrimmableTypeMapGenerator.cs Supplies generated-peer names throughout reference validation.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​README.md Documents generated top-level and external nested-name behavior.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​JavaNameValidator.cs Preserves complete generated identifiers during validation.

Review effort: Balanced

@simonrozsival simonrozsival changed the title [TrimmableTypeMap] Backport generated Java name validation [release/11.0.1xx][TrimmableTypeMap] Validate generated top-level Java identifiers Nov 5, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member

/review

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13405

@github-actions github-actions Bot 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.

✅ LGTM — code review

0 errors · 0 warnings · 1 non-blocking suggestion (inline).

The backport aligns validation with the existing Java source emitter: generated top-level identifiers preserve $, while external nested types still receive segment-by-segment validation. Package and whole-identifier checks remain in place before the generated-peer exemption. I checked constructor/method descriptors, fields, inheritance/interfaces, thrown types, and deferred registration against their consumers. The release-specific xUnit adaptations and expanded same-/cross-assembly component build matrix cover the intended behavior. No merge-blocking code issues found.

CI: All 45 returned GitHub checks report success, including the aggregate dotnet-android check for Azure build 1665919. Direct Azure build/timeline queries require authentication in this environment, so I could not independently verify the Azure result beyond those checks.

Local validation: Attempted dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj --no-restore -v minimal --filter 'FullyQualifiedName~TrimmableTypeMapJavaNameTests|FullyQualifiedName~TrimmableTypeMapGeneratorTests.ValidateJavaNames|FullyQualifiedName~JavaNameValidatorTests'. The CLI failed before test execution with an IOException initializing the NuGet-Migrations mutex; no local test results were produced. The passing local results documented in the PR were not independently reproduced here.

Generated by Android PR Reviewer for #13405 · copilot · gpt61 · 53.6 AIC · ⌖ 4.54 AIC · ⊞ 20.1K
Comment /review to run again

var java = new JcwJavaSourceGenerator ().GenerateContent ([target, consumer])
.Single (source => source.RelativePath == "example/Consumer.java").Content;
string expectedTypeName = "example.components." + (external ? simpleName.Replace ('$', '.') : simpleName);
Assert.Contains (expectedTypeName, java);

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.

🤖 💡 Testing — Consider asserting the expected declaration/signature for each referenceKind, rather than just finding the type name anywhere in the source. For the method case, the same name appears in the scalar parameter, array parameter, array return type, and native declaration; this assertion still passes if only one occurrence is converted correctly or an array suffix is lost. Checking the complete echo signature (and both constructor overload shapes where applicable) would make this matrix verify each emitted position it exercises.

{Rule: Test assertions must be specific; test final generated-source output}

@jonathanpeppers jonathanpeppers 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.

Let's wait to merge this until we are sure release/11.0.1xx is clear for GA.

Later this week.

@jonathanpeppers jonathanpeppers added do-not-merge PR should not be merged. and removed do-not-merge PR should not be merged. labels Nov 9, 2026
@jonathanpeppers
jonathanpeppers merged commit 7011baa into release/11.0.1xx Nov 10, 2026
45 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-backport-jni-name-validation branch November 10, 2026 19:33
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.

3 participants