Skip to content

NPE in EcoreGeneratorFragment2: genModel is null when not configured in MWE2 #1309

@joaodinissf

Description

@joaodinissf

Description

EcoreGeneratorFragment2.generate() passes this.genModel (which may be null) to CustomClassAwareEcoreGenerator.setGenModel(), then calls preInvoke() which does URI.createURI(genModel) → NPE.

java.lang.NullPointerException: Cannot invoke "String.indexOf(int)" because "uri" is null
    at org.eclipse.emf.common.util.URI.createURIWithCache(URI.java:2577)
    at org.eclipse.emf.common.util.URI.createURI(URI.java:2455)
    at c.a.t.d.xtext.generator.util.CustomClassAwareEcoreGenerator.preInvoke(CustomClassAwareEcoreGenerator.java:163)
    at c.a.t.d.xtext.generator.ecore.EcoreGeneratorFragment2.generate(EcoreGeneratorFragment2.java:94)

Root cause

In GenerateTestLanguage.mwe2 line 68, the fragment is used with empty config:

fragment = ecore.EcoreGeneratorFragment2 {}

Unlike the standard EMFGeneratorFragment2 (which derives the genModel from the Xtext language config), the DDK fragment requires genModel to be set explicitly but doesn't guard against null.

Introduced

Commit 45aed05d7 (Feb 2022, "Migrate away from legacy Xtext generator"). The bug has been latent for 4 years — the fragment is only used in GenerateTestLanguage.mwe2 and the NPE doesn't block the build since the standard EMFGeneratorFragment2 on the preceding line does the main work.

Fix options

  1. Guard: skip preInvoke()/invoke() when genModel is null
  2. Derive: resolve genModel from the Xtext IXtextGeneratorLanguage configuration like the standard fragment does
  3. Remove: if the fragment isn't needed after EMFGeneratorFragment2 runs, delete it from the MWE2 workflow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions