Employing multiple generators via forking generation plan leads to NullPointerException

TL;DR:

  • My goal is to create a language with two independent and alternative generators. I heard having >= 2 generators should be supported in MPS 2020.1.2.
  • In my sample project (cf. first screenshot), I managed to successfully have two almost empty plaintextgen generators with the procedure detailled below. By almost empty, I mean that the moment I try to access a property of my root concept in those generators, generation fails with a NullPointerException (cf. below).
  • MPS project files: https://github.com/ComFreek/mps-two-generatos-bug-repro

Long Explanation:

In the screenshot of the project structure below, you can see I have two generator modules for my language called FirstSemantics and SecondSemantics. They both have only a single template for the single concept in my language (RootConcept), see the screenshot for FirstSemantics.txt below. Concretely, they both use plaintextgen as an output model and interpolate the msg property of RootConcept whose type is the built-in string type.

The solution project is set up to use a custom generation plan, namely TestLang.forkGenerationPlans@genplan. That one just forks into the other two generation plans: JustInvokeFirstSemantics, JustInvokeSecondSemantics

Now the NullPointerException occurs if I right-click my ExemplaryRootConcept solution model and choose Preview Generated Text. Moreover, I don't get any generator output at all. If I simply remove the property accesses to msg in both generator templates, Preview Generated Text works fine: it opens two new tabs for both generated files.

 

```

Generation plan for model TestSolution2.Sandbox defined with a custom module facet
(jetbrains.mps.generator.impl.GenerationFailureException): unexpected exception when applying root rule
jetbrains.mps.generator.impl.GenerationFailureException: unexpected exception when applying root rule
at jetbrains.mps.generator.template.DefaultQueryExecutionContext.applyRule(DefaultQueryExecutionContext.java:251)
at jetbrains.mps.generator.impl.TemplateGenerator.createRootNodeByRule(TemplateGenerator.java:400)
at jetbrains.mps.generator.impl.TemplateGenerator.applyRootRule(TemplateGenerator.java:385)
at jetbrains.mps.generator.impl.TemplateGenerator.applyRootRule(TemplateGenerator.java:380)
at jetbrains.mps.generator.impl.TemplateGenerator.applyReductions(TemplateGenerator.java:293)
at jetbrains.mps.generator.impl.TemplateGenerator.apply(TemplateGenerator.java:181)
[...]
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at jetbrains.mps.generator.impl.GeneratorUtil.getTemplateNodeId(GeneratorUtil.java:101)
at jetbrains.mps.generator.impl.TemplateNode.<init>(TemplateNode.java:73)
at jetbrains.mps.generator.impl.TemplateProcessor.getTemplateNodeRuntime(TemplateProcessor.java:166)
at jetbrains.mps.generator.impl.TemplateProcessor.apply(TemplateProcessor.java:100)
at jetbrains.mps.generator.impl.interpreted.TemplateRootMappingRuleInterpreted.apply(TemplateRootMappingRuleInterpreted.java:78)
at jetbrains.mps.generator.template.DefaultQueryExecutionContext.applyRule(DefaultQueryExecutionContext.java:247)
... 33 more
Generation failed for model 'TestSolution2.Sandbox': unexpected exception when applying root rule. java.lang.NullPointerException
-- -- was input node: [root] RootConcept "ExemplaryRootConcept"[737147979933238729] in TestSolution2.Sandbox@1_101
generation completed with errors in 1 ms
Error executing target jetbrains.mps.lang.core.Generate.generate
"configure" target execution time: 7 ms
"generate" target execution time: 3 ms
Other targets execution time: 0 ms; preloadModels: 0 ms, checkParameters: 0 ms
Rebuild failed. See previous messages for details.

```

Screenshot of project structure:

Screenshot of the template FirstSemantics.txt. The one for SecondSemantics.txt is analogous -- it just have different constant strings in filename and text.

 

 

 

1 comment
Comment actions Permalink

I tried your project from GitHub in MPS 2020.1.2 and it worked, I have both text files generated and no error. I did get a NPE at first but I found I also haven't installed the plaintextgen plugin. After installing it, restarting MPS and rebuilding the entire project everything worked.

0

Please sign in to leave a comment.