Skip to content

[TrimmableTypeMap] Validate generated top-level Java identifiers - #13311

Merged
simonrozsival merged 1 commit into
mainfrom
simonrozsival-component-jni-name-review
Nov 5, 2026
Merged

simonrozsival merged 1 commit into
mainfrom
simonrozsival-component-jni-name-review

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

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.

Validation

Commands omit only log redirection and TRX-output options. All application builds use the freshly built local SDK.

  • make prepare — passed.
  • make leeroy — passed, including the solution build, extra API levels, and local workload configuration.
  • ./dotnet-local.sh test bin/TestDebug/net11.0/Microsoft.Android.Build.Tasks.Tests.dll -v minimal --filter 'FullyQualifiedName~TrimmableTypeMap' — passed: 105 tests, 0 failures, 0 skips, including all 58 new regression cases.
  • ./dotnet-local.sh test src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj -v minimal --filter 'FullyQualifiedName~Build_ComponentNameIsUsedInSignatures' — passed: 72 tests, 0 failures, 0 skips. Verified the TRX contains exactly the expected 72 unique combinations, including all 24 Outer$for cases.
  • ./dotnet-local.sh test src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj --no-build -v minimal --filter 'FullyQualifiedName~Build_InvalidOrUnsupportedUnicodeIdentifiers|FullyQualifiedName~Build_JavaTypeOnlyIdentifierStarts|FullyQualifiedName~Build_SupplementaryJavaIdentifier' — passed: 6 tests, 0 failures, 0 skips.

No device execution was performed. This PR targets main; the release backport is not included.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 13:26

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 changes.

No open issues 🎉

What changed in this PR

Aligns trimmable typemap validation with the source-generation behavior introduced in #13147, allowing generated top-level Java names such as Outer$for without relaxing validation for external nested types.

Changes:

  • Passes generated-peer names through source-type, JNI descriptor, throws-clause, and deferred-registration validation.
  • Adds 58 focused regression cases and expands the application-build matrix to 72 cases with Outer$for.
  • Documents the distinction between generated top-level wrappers and external nested Java types.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Adds Outer$for to the component-name build matrix.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​TrimmableTypeMapGenerator.cs Supplies generated-peer names to relevant validation paths.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​README.md Explains top-level versus nested identifier handling.
src/​Microsoft.Android.Sdk.TrimmableTypeMap/​JavaNameValidator.cs Validates generated dollar-containing identifiers as complete names.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​TrimmableTypeMapJavaNameTests.cs Adds focused identifier and source-reference regression coverage.

Review effort: Balanced

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.

Local validation passes: `make prepare`, `make leeroy`, 105 trimmable-typemap task tests, all 72 component-signature application-build cases, and six existing invalid-name diagnostic application-build cases.  No device execution is performed.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival force-pushed the simonrozsival-component-jni-name-review branch from 9cd857b to 51a5756 Compare November 4, 2026 13:27
@simonrozsival

Copy link
Copy Markdown
Member Author

@dalexsoto review

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

@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 complete five-file PR diff, current discussion, and material validator, scanner, Java/JNI source and descriptor emission, deferred-registration, manifest, CoreCLR/NativeAOT and test/documentation integration, followed by a separate final independent-blocker pass.

The generated-peer name set preserves dollar-containing top-level identifiers while retaining package and complete-identifier validation and external nested-type checks. The default-package throws and deferred Application/Instrumentation paths are consistent with that distinction. The accepted forward-compatible identifier policy is preserved. No high-confidence blocking issue remains.

Static source review at 51a5756d5647d7bd37757db50082c621bc57e094, actual target 510f36d8fc0ad797902ce65c9fdbe139899a8651, comparison/merge-base ce24a04582445ea4430f625833ce380d9707cb03; no builds, tests, generators or CI were executed. Author-reported results are not independently executed validation or generated-output parity.

@simonrozsival
simonrozsival merged commit 536fa66 into main Nov 5, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-component-jni-name-review branch November 5, 2026 12:24
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.

3 participants