Repository navigation
[release/11.0.1xx][TrimmableTypeMap] Validate generated top-level Java identifiers - #13405
jonathanpeppers merged 2 commits into
Conversation
) 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]>
There was a problem hiding this comment.
🟢 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
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
✅ 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); |
There was a problem hiding this comment.
🤖 💡 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
left a comment
There was a problem hiding this comment.
Let's wait to merge this until we are sure release/11.0.1xx is clear for GA.
Later this week.
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 asexample.components.Outer$fortherefore 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:
-xattribution.Local validation
make prepare— passed.make leeroy— passed; builds the SDK, extra stable API levels, and local workload. Used instead ofmake allbecause 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):
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.mdworkflow documentation, and in particular should include: