Skip to content

fix: derive a valid package for shallow export model URIs in ExportGeneratorX#1281

Open
joaodinissf wants to merge 1 commit into
dsldevkit:masterfrom
joaodinissf:fix/export-generatorx-uri-guard
Open

fix: derive a valid package for shallow export model URIs in ExportGeneratorX#1281
joaodinissf wants to merge 1 commit into
dsldevkit:masterfrom
joaodinissf:fix/export-generatorx-uri-guard

Conversation

@joaodinissf

@joaodinissf joaodinissf commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

ExportGeneratorX.getPrefix derives the target package from raw URI segment arithmetic and misbehaves on every short URI shape:

  • 1 segment (e.g. ParseHelper's __synthetic0.export): subList(-1, 0)IndexOutOfBoundsException.
  • 2 segments: emits the literal segment resource as the package.
  • project root (platform:/resource/<project>/<file>.export): emits the raw project name — uncompilable generated code when the project is not named like a Java package (e.g. My-Project).
  • source-folder root (<project>/src/<file>.export): emits an empty package, producing leading-dot qualified names (.naming.…).

The derived value feeds both the generated package declaration and the output file path via the six accessor methods (ExportedNamesProvider, ResourceDescriptionManager/Strategy/Constants, FingerprintComputer, FragmentProvider).

The fix is confined to that one method:

  • URIs with five or more segments keep the previous derivation byte for byte (segments between position 3 and the file, regardless of the source folder's name) — no behavior change for any layout that worked before, including src-gen nesting and src/main/java.
  • Shorter shapes fall back to the project name when it already is a valid Java package name (SourceVersion.isName, byte-identical to previous behavior for the project-root shape), or generated otherwise.

No existing test ever failed on this: the builder participant catches the exception per resource and logs it — the long-standing ERROR … Error during compilation of '….export' noise in every master test run — and the export tests assert validation/scoping, never generated output (that structural gap is addressed separately by #1459). The new ExportGeneratorXTest pins the shape table with synthetic resource URIs; no fixture files needed.

Verification

  • Full local gate on this head: mvn -T 3C clean verify checkstyle:check pmd:check pmd:cpd-check spotbugs:check → BUILD SUCCESS, 0 test failures, including the new ExportGeneratorXTest (runs in CI via ExportTestSuiteAllTests).
  • A/B: the new tests grafted onto plain master (production code unchanged) fail on exactly the broken shapes — IndexOutOfBoundsException: fromIndex = -1 for the single-segment URI and wrong/leading-dot packages for the short shapes — while the behavior-preservation tests (nested derivations, valid project-name fallback) pass on both master and this branch.

🤖 Generated with Claude Code

@joaodinissf joaodinissf changed the title fix: harden ExportGeneratorX package derivation fix: handle shallow export resource URIs in ExportGeneratorX Mar 3, 2026
@joaodinissf joaodinissf marked this pull request as draft March 3, 2026 21:01
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch from 0f6cf8b to 5b9f831 Compare March 3, 2026 23:15
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch from 5b9f831 to bfc4e37 Compare April 4, 2026 11:37
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch 2 times, most recently from b096715 to d0a7d5f Compare April 20, 2026 08:21
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch 2 times, most recently from 5938031 to 4ee1c4e Compare June 2, 2026 16:56
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch 2 times, most recently from adcaf41 to 58aff88 Compare July 10, 2026 14:17
@joaodinissf joaodinissf changed the title fix: handle shallow export resource URIs in ExportGeneratorX fix: derive a valid package for shallow export model URIs in ExportGeneratorX Jul 10, 2026
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch from 58aff88 to f3f4e1a Compare July 10, 2026 19:18
@joaodinissf joaodinissf marked this pull request as ready for review July 10, 2026 22:19
@joaodinissf joaodinissf requested a review from rubenporras July 10, 2026 22:19
…neratorX

ExportGeneratorX.getPrefix derives the target package from raw URI
segment arithmetic and misbehaves on every short URI shape: 1 segment
(e.g. ParseHelper's __synthetic0.export) crashes with
IndexOutOfBoundsException (subList(-1, 0)); 2 segments emit the literal
segment "resource"; project-root URIs emit the raw project name
(uncompilable generated code when the project is not named like a Java
package); source-folder-root URIs emit an empty package, producing
leading-dot qualified names.

Keep the derivation for URIs with five or more segments byte for byte
(segments between position 3 and the file) and make every shorter shape
fall back to the project name when it already is a valid Java package
name (SourceVersion.isName) or "generated" otherwise.

No existing test ever failed on this: the builder participant catches
the exception per resource and logs it (the long-standing "Error during
compilation of '....export'" noise in master test runs), and export
tests never assert generated output. ExportGeneratorXTest pins the full
shape table with synthetic resource URIs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ANGM7L3BaEGfGUmPVKRt4
@joaodinissf joaodinissf force-pushed the fix/export-generatorx-uri-guard branch from f3f4e1a to 793edf0 Compare July 11, 2026 13:43
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.

1 participant