[typemap] Preserve supported Unicode JCW names - #12607
Open
simonrozsival wants to merge 4 commits into
Open
Conversation
Allow BMP letter identifiers to flow unchanged through trimmable JCW generation and diagnose name categories that Android tooling cannot carry consistently. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Microsoft.Android.Sdk.TrimmableTypeMap/JavaNameValidator.cs — 💡 suggestion — When a package/JNI name contains an empty segment (e.g. consecutive separators),… |
What changed in this PR
This PR extends the trimmable typemap/JCW pipeline to preserve supported BMP Unicode Java identifiers end-to-end (typemap keys, JCW source paths/declarations, ACW mappings, manifest component names, DEX, and runtime/JNI activation), while rejecting unsupported Unicode forms early via XA4258.
Changes:
- Tighten Java/JNI name validation to accept a constrained set of stable BMP identifiers and reject combining/format/supplementary code points with XA4258.
- Add generator + integration + device/runtime coverage to prove Unicode identifiers survive generation/compilation/activation across llvm-ir/CoreCLR/NativeAOT matrices.
- Update XA4258 wording and documentation to reflect the broader “invalid or unsupported” identifier class.
| File | Description |
|---|---|
| tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs | Adds device activation test for an Activity with a Unicode Java identifier. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs | Adds Java-side constructor/peer-registration test for a Unicode-registered type. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TypeMapModelBuilderTests.cs | Verifies typemap model preserves Unicode code points in map keys/JNI names. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs | Expands XA4258 validation coverage for unsupported Unicode/identifier shapes and updates expected message text. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/ManifestGeneratorTests.cs | Ensures manifest component names preserve Unicode code points. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs | Extends JNI name validation tests for decomposed/supplementary forms and validates a Unicode-good case. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JavaNameValidatorTests.cs | Adds focused unit tests for valid BMP Unicode identifiers and rejected unsupported cases. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/AcwMapWriterTests.cs | Verifies ACW map writing preserves Unicode identifiers. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/JavaSourceSemanticParityTests.cs | Adds semantic parity compilation path assertions for Unicode-generated Java artifacts. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/JavaSourceParityFixture/JavaSourceParityTypes.cs | Adds a fixture Activity registered under a Unicode Java name. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | Adds build-time assertions that Unicode names survive intermediate outputs/manifest/acw-map and documents DEX limitations for supplementary code points. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | Updates XA4258 resource text to “invalid or unsupported”. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs | Regenerates designer text for the updated XA4258 resource. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/JavaNameValidator.cs | Implements restricted Unicode identifier support/validation logic for stable toolchain behavior. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JniSignatureHelper.cs | Routes JNI-name validation through the centralized JavaNameValidator checks and updates exception text. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs | Updates documentation for what JNI-name validation now enforces. |
| Documentation/docs-mobile/messages/xa4258.md | Updates XA4258 docs to explain unsupported Unicode categories and toolchain constraints. |
| Documentation/docs-mobile/messages/index.md | Updates XA4258 index entry to match new wording. |
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
Suppressed comments (1)
src/Microsoft.Android.Sdk.TrimmableTypeMap/JavaNameValidator.cs:98
- 💡 suggestion — Similar to package validation,
TryGetInvalidJniNameSegmentcan report an empty invalidSegment for malformed JNI names (leading/trailing/consecutive/). That produces error text likeidentifier ''. Substituting a placeholder makes XA4258/ArgumentException messages clearer.
var segments = jniName.Split ('/');
for (int i = 0; i < segments.Length - 1; i++) {
if (IsInvalidIdentifier (segments [i], isTypeName: false)) {
invalidSegment = segments [i];
return true;
}
Comment on lines
80
to
84
| foreach (var segment in packageName.Split (separator)) { | ||
| if (JavaKeywords.Contains (segment)) { | ||
| if (IsInvalidIdentifier (segment, isTypeName: false)) { | ||
| invalidSegment = segment; | ||
| return true; | ||
| } |
Classify BMP identifiers from OpenJDK 21 Unicode 15 data, require NFC names, and distinguish portable type starts from Android package and manifest constraints. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve manifest placeholders before validation and alias rewriting, decode DEX and classfile modified UTF-8 exactly, and record the supplementary class-loader limitation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve manifest packages and placeholders consistently before deduplication, and validate DEX and modified UTF-8 inputs without lossy or unbounded decoding. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
27 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes part of #12561.
Validation