Skip to content

[CoreCLR] Validate Java package and type names - #12323

Open
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers-validate-java-names
Open

[CoreCLR] Validate Java package and type names#12323
jonathanpeppers wants to merge 1 commit into
mainfrom
jonathanpeppers-validate-java-names

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Java keywords in application package or Java peer type names currently reach generated Java source and fail later in javac with an unclear JAVAC0000 error.

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 passed
  • GetAndroidPackageNameTests: 4 passed
  • Xamarin.Android.Build.Tasks.csproj isolated compile succeeded

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>
Copilot AI review requested due to automatic review settings August 7, 2026 20:31

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.

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 JavaNameValidator and integrated it into GetAndroidPackageName and 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Putting Java keyword in a package/type name breaks javac compilation

2 participants