Skip to content

Move hardcoded error strings in JCWGenerator.cs to Properties.Resources with XA error codes#11427

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-move-hardcoded-error-strings
Open

Move hardcoded error strings in JCWGenerator.cs to Properties.Resources with XA error codes#11427
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-move-hardcoded-error-strings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Four LogError calls in JCWGenerator.cs used hardcoded interpolated strings instead of localized resource strings with XA#### codes. This replaces them with LogCodedError using new resource entries.

New error codes

  • XA4253 — Generated JCW code changed unexpectedly (line 110)
  • XA4217 — Architecture has Java types missing from template architecture (lines 191-196, consolidated from per-type loop into single message)
  • XA4227 — Marshal method mismatch across architectures (line 271)

Changes

  • Properties/Resources.resx / Resources.Designer.cs — Added XA4253, XA4217, XA4227 resource strings
  • Utilities/JCWGenerator.cs — Replaced LogErrorLogCodedError at all four call sites; collapsed the type-list loop into a single sorted, string.Join'd message
  • Documentation/docs-mobile/messages/ — Added xa4253.md, xa4217.md, xa4227.md; updated index.md
// Before
logger.LogError ($"Architecture '{state.TargetArch}' has Java types which have no counterparts in template architecture '{templateState.TargetArch}':");
foreach (var type in typesSet)
    logger.LogError ($"  {type}");

// After
typesSet.ExceptWith (templateSet);
var typesList = string.Join (", ", typesSet.OrderBy (t => t, StringComparer.Ordinal));
logger.LogCodedError ("XA4217", Properties.Resources.XA4217, state.TargetArch, templateState.TargetArch, typesList);

Note: XA4253 was chosen instead of XA4212 because XA4212 is already used in XAJavaTypeScanner.cs for the IJavaObject without Java.Lang.Object error. XA4217 is also used in external/Java.Interop for a Kotlin method override error (different resource key JavaCallableWrappers_XA4217). The index lists both uses.

…es with XA error codes

Add XA4212, XA4217, XA4227 resource strings and replace LogError calls
with LogCodedError in JCWGenerator.cs. Create documentation files for
each new error code and update the error code index.

Agent-Logs-Url: https://github.com/dotnet/android/sessions/4696467d-3a7f-4b52-a92d-5e884cb5bad1

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix move hardcoded error strings in JCWGenerator to Resources Move hardcoded error strings in JCWGenerator.cs to Properties.Resources with XA error codes May 20, 2026
Copilot AI requested a review from jonathanpeppers May 20, 2026 20:31
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 20, 2026 20:36
Copilot AI review requested due to automatic review settings May 20, 2026 20:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates JCWGenerator error reporting to use localized Properties.Resources strings and LogCodedError calls with XA error codes, and adds corresponding documentation pages for the new/updated messages.

Changes:

  • Replaced hardcoded LogError strings in Utilities/JCWGenerator.cs with LogCodedError and new resource entries (XA4212/XA4217/XA4227).
  • Added new XA resource strings to Properties/Resources.resx (and updated Resources.Designer.cs).
  • Added message documentation pages (xa4212.md, xa4217.md, xa4227.md) and updated Documentation/docs-mobile/messages/index.md.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs Switches several error logs to LogCodedError and consolidates one multi-line error into a single message.
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds new XA resource strings used by JCWGenerator.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Regenerates resource accessors for the new XA entries.
Documentation/docs-mobile/messages/xa4212.md Adds docs page for XA4212.
Documentation/docs-mobile/messages/xa4217.md Adds docs page for XA4217.
Documentation/docs-mobile/messages/xa4227.md Adds docs page for XA4227.
Documentation/docs-mobile/messages/index.md Adds entries linking to the new XA docs pages.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Language not supported

Comment thread src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs Outdated
Comment thread src/Xamarin.Android.Build.Tasks/Utilities/JCWGenerator.cs Outdated
Comment thread Documentation/docs-mobile/messages/xa4212.md Outdated
Comment thread Documentation/docs-mobile/messages/xa4217.md Outdated
Comment thread Documentation/docs-mobile/messages/xa4227.md Outdated
@jonathanpeppers
Copy link
Copy Markdown
Member

@copilot address the code review comments where they are relevant and explain what you did in detail.

- Rename XA4212 to XA4253 to avoid conflicting with existing XA4212 in
  XAJavaTypeScanner.cs (IJavaObject without Java.Lang.Object).
- Sort type names with StringComparer.Ordinal before joining for
  deterministic error messages across runs.
- Fix double spaces after periods in xa4253.md, xa4217.md, xa4227.md
  to match single-space convention used in other doc files.

Agent-Logs-Url: https://github.com/dotnet/android/sessions/38e8cd39-9d56-407f-81ca-76b35be25ccd

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 20, 2026

@copilot address the code review comments where they are relevant and explain what you did in detail.

Addressed all relevant review comments in edc6d32:

  1. XA4212 conflict — Renamed to XA4253 (unused code) since XA4212 is already used in XAJavaTypeScanner.cs for the IJavaObject without Java.Lang.Object error. Updated resource entries, JCWGenerator.cs, documentation file (renamed xa4212.mdxa4253.md), and index.md.

  2. Non-deterministic type list ordering — Added .OrderBy(t => t, StringComparer.Ordinal) before string.Join so the type list in XA4217 messages is sorted and stable across runs/machines.

  3. Double spaces after periods — Fixed all three doc files (xa4253.md, xa4217.md, xa4227.md) to use single spaces, matching the convention in other message docs.

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.

[fix-finder] Move hardcoded error strings in JCWGenerator.cs to Properties.Resources with XA error codes

3 participants