[CoreCLR] Validate Java package and type names - #12323
Open
jonathanpeppers wants to merge 1 commit into
Open
Conversation
Report XA4258 before javac when an application package or Java peer type uses a reserved Java identifier. Add Java SE 21 references, message documentation, and focused unit coverage. Fixes #7489 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds early validation for Java reserved identifiers in application package names and CoreCLR trimmable type-map JNI names, surfacing a clear XA4258 diagnostic instead of failing later in javac with JAVAC0000.
Changes:
- Introduced
JavaNameValidatorand integrated it intoGetAndroidPackageNameand the trimmable type-map generation flow to detect reserved identifiers early. - Added new localized error XA4258 plus documentation entries (message page, index, TOC).
- Added focused unit tests covering reserved identifiers, restricted type identifiers, contextual keywords, and valid names.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs | Adds generator-level tests for XA4258 logging and contextual keyword allowance. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs | Extends JNI name validation coverage to include reserved/restricted identifiers. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JavaNameValidatorTests.cs | New test suite covering reserved identifiers, restricted type identifiers, and contextual keywords. |
| src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj | Links JavaNameValidator.cs into Build.Tasks for shared validation logic. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAndroidPackageNameTests.cs | New tests ensuring package keywords fail with XA4258 and contextual keywords succeed. |
| src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidPackageName.cs | Adds XA4258 validation for canonicalized application/package names. |
| src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs | Plumbs XA4258 logging and stops before writing outputs when errors are logged. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | Adds localized XA4258 message text. |
| src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs | Adds generated accessor for XA4258 resource. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs | Adds early validation pass over scanned peers to emit XA4258 and abort generation. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/JavaNameValidator.cs | New validator for reserved keywords/literals and restricted type identifiers (type-name position). |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/ITrimmableTypeMapLogger.cs | Extends logger interface with LogInvalidJavaNameError. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JniSignatureHelper.cs | Extends JNI name validation to reject reserved/restricted identifiers. |
| Documentation/docs-mobile/TOC.yml | Registers XA4258 documentation page in the docs TOC. |
| Documentation/docs-mobile/messages/xa4258.md | New message documentation page for XA4258. |
| Documentation/docs-mobile/messages/index.md | Adds XA4258 to the messages index. |
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
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.
Java keywords in application package or Java peer type names currently reach generated Java source and fail later in
javacwith an unclearJAVAC0000error.Add early XA4258 validation for application package names and CoreCLR trimmable type-map JNI names. The validator follows the Java SE 21 identifier rules, permits contextual keywords where Java allows them, and rejects restricted identifiers for type names. The typemap task stops before writing outputs after reporting the diagnostic.
Add localized error resources, message documentation, and focused unit tests covering all reserved identifiers, restricted type identifiers, contextual keywords, and valid names.
Fixes #7489
Tests:
Microsoft.Android.Sdk.TrimmableTypeMap.Tests: 771 passedGetAndroidPackageNameTests: 4 passedXamarin.Android.Build.Tasks.csprojisolated compile succeeded