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
- Guard: skip
preInvoke()/invoke() when genModel is null
- Derive: resolve
genModel from the Xtext IXtextGeneratorLanguage configuration like the standard fragment does
- Remove: if the fragment isn't needed after
EMFGeneratorFragment2 runs, delete it from the MWE2 workflow
Description
EcoreGeneratorFragment2.generate()passesthis.genModel(which may be null) toCustomClassAwareEcoreGenerator.setGenModel(), then callspreInvoke()which doesURI.createURI(genModel)→ NPE.Root cause
In
GenerateTestLanguage.mwe2line 68, the fragment is used with empty config:Unlike the standard
EMFGeneratorFragment2(which derives the genModel from the Xtext language config), the DDK fragment requiresgenModelto 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 inGenerateTestLanguage.mwe2and the NPE doesn't block the build since the standardEMFGeneratorFragment2on the preceding line does the main work.Fix options
preInvoke()/invoke()whengenModelis nullgenModelfrom the XtextIXtextGeneratorLanguageconfiguration like the standard fragment doesEMFGeneratorFragment2runs, delete it from the MWE2 workflow