Skip to content

fix: tolerate an unresolvable grammar in export model generation#1459

Draft
joaodinissf wants to merge 2 commits into
dsldevkit:masterfrom
joaodinissf:fix/export-generatorx-uri-guard-step-2
Draft

fix: tolerate an unresolvable grammar in export model generation#1459
joaodinissf wants to merge 2 commits into
dsldevkit:masterfrom
joaodinissf:fix/export-generatorx-uri-guard-step-2

Conversation

@joaodinissf

Copy link
Copy Markdown
Collaborator

Stacked on #1281.

Summary

ExportGeneratorX.getGrammar demand-loads the sibling <name>.xtext next to an export model (resourceSet.getResource(..., true)). For any model without such a sibling — every test .export file, models built via ParseHelper — the load throws, so the Xtext builder participant logs Error during compilation of '<file>' with a full stack trace and silently aborts generation for that file. Every full test run carries dozens of these ERROR entries, and the generator's main path never actually executes over the test fixtures.

This makes grammar resolution defensive: guard a missing resource/resource set, reject unresolved targetGrammar proxies, catch the demand-load failure — return null. Downstream, GeneratorUtil.allInstantiatedTypes treats a null grammar as "no parser-instantiated subtypes" (one guard covering both typeMap and canContain — exercising generation past the resolver for the first time exposed this second latent NPE), and the remaining call sites already tolerate a null grammar (grammar?.name ?: … in ExportedNamesProviderGenerator; explicit null check in ResourceDescriptionManagerGenerator). Export model generation now degrades gracefully (direct type mappings, no subtype expansion) instead of aborting.

Phase 0 of #1458 (role-aware package identity): resolution failure must select the fallback, never fail generation.

Verification

  • New testGetGrammarReturnsNullWithoutResolvableGrammar covers the resolver matrix: detached model, resource without resource set, missing sibling grammar, unresolved targetGrammar proxy.
  • Full local gate: mvn -T 3C clean verify pmd:check checkstyle:check spotbugs:check → BUILD SUCCESS; Error during compilation entries for export fixtures gone from the AllTests log (baseline: ~25 per run).
  • CI green.

🤖 Generated with Claude Code

…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
The sibling-grammar lookup in ExportGeneratorX.getGrammar demand-loads
<name>.xtext next to the export model; for models with no such sibling
(every test .export file, models built via ParseHelper) the load throws
and the builder participant logs "Error during compilation" and silently
aborts generation for the file — dozens of ERROR entries in every full
test run, and the generator's main path never executes over the test
fixtures.

Make grammar resolution defensive: guard a missing resource or resource
set, reject unresolved targetGrammar proxies, and catch the demand-load
failure, returning null. Downstream, GeneratorUtil.allInstantiatedTypes
treats a null grammar as "no parser-instantiated subtypes" (covering
typeMap and canContain), and the remaining generator call sites already
tolerate a null grammar (grammar?.name in ExportedNamesProviderGenerator;
an explicit null check in ResourceDescriptionManagerGenerator). Export
model generation now degrades gracefully instead of aborting.

Phase 0 of dsldevkit#1458.
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