NullPointerException in Xtext IDE project after removing generate model statement from grammar [message #1852034] |
Tue, 26 April 2022 13:58  |
Eclipse User |
|
|
|
I am developing a grammar from an existing specification. Therefore I used some import statements in the grammar to import existing ecore EPackages (created from XML schemas) and implemented a simple grammar for some types in these existing EPackages. This grammar worked as expected.
Next, I wanted to benefit from Xtext's cross referencing functionality to improve some of the grammar. So I added a generate statement to create a new EPackage and added a new grammar rule that defines a cross reference. This grammar that combines imported and generated EPackages worked for my test.
However, this will not work for my use case due the requirement to only use the imported EPackages (existing specification), so I removed the generate statement, as well as my new grammar rule that I added. Unfortunately, this is where I ran into trouble.
My project is using Gradle as the build system. But, when I tried to build this grammar again (the one after I removed the generated EPackage), my basic parsing test failed during the build. So, I disabled this parsing test, to let the build finish for now. Then I starting debugging. I have created a run configuration for the Xtext Language Server in the project, so I can debug in Eclipse.
This error appears in the console log when I try to use content assist to fetch proposed auto completions in the editor (using keybind 'CTRL+SPACE' in Eclipse).
SEVERE: Internal error: java.lang.NullPointerException: parseResult is null
java.util.concurrent.CompletionException: java.lang.NullPointerException: parseResult is null
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346)
at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:704)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
at org.eclipse.xtext.ide.server.concurrent.AbstractRequest.logAndCompleteExceptionally(AbstractRequest.java:73)
at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:69)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException: parseResult is null
at org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory.create(ContentAssistContextFactory.java:130)
at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createProposals(ContentAssistService.java:104)
at org.eclipse.xtext.ide.server.contentassist.ContentAssistService.createCompletionList(ContentAssistService.java:78)
at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$23(LanguageServerImpl.java:555)
at org.eclipse.xtext.ide.server.WorkspaceManager.doRead(WorkspaceManager.java:438)
at org.eclipse.xtext.ide.server.LanguageServerImpl.completion(LanguageServerImpl.java:554)
at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$completion$22(LanguageServerImpl.java:540)
at org.eclipse.xtext.ide.server.concurrent.ReadRequest.lambda$doRun$0(ReadRequest.java:66)
... 5 more
This exception is being thrown in the org.eclipse.xtext.ide.editor.contentassist.antlr.ContentAssistContextFactory class after it checks that 'parseResult' is null.
public ContentAssistContext[] create(String document, ITextRegion selection, int offset, XtextResource resource) {
this.document = document;
this.selection = selection;
this.resource = resource;
//This is called to make sure late initialization is done.
if (resource instanceof DerivedStateAwareResource) {
resource.getContents();
}
// OP: This is the method call that returns null when I do not have a generate statement in my grammar
this.parseResult = resource.getParseResult();
if (parseResult == null)
throw new NullPointerException("parseResult is null");
return doCreateContexts(offset);
}
I do not know why this error occurs now. I have tested with the grammar that generates a new EPackage and the parseResult is a valid AST containing my model. So the problem only occurs when I remove the 'generate' statement in the grammar.
To be clear, there are no build problems in the project and the Gradle clean build is completing successfully (after removing the parsing test). There are no errors compiling or running the project. However, when I interact with the Eclipse text editor which communicates with the Xtext Language Server, I get this runtime exception.
I do not know enough about Xtext or EMF to know why this is occurring.
For now, I have used a hack to get this project to work again, whereby I made a 'dummy' grammar rule that only has a single feature that references an existing grammar rule from an imported EPackage (this is a reference to an EDatatype that returns a string) Consequently, I have left the 'generate' statement in the grammar to allow this.
Also, simply having a generated model (EPackage) is not enough. I tried with a 'dummy' grammar rule that only references a terminal rule (f.e. ID), but it seems to want a link between the generated ecore and an imported ecore, else this 'parseResult' is null.
This 'dummy' grammar rule cannot be matched in a text by the parser, but simply having it exist is somehow required to get the parser to return a valid model for me. I'm out of ideas about why this is happening, and would like to know how to fix this properly, before I resort to starting over in a new Xtext project.
Installed versions:
Eclipse Xtext Xtext 2.26.0.v20211001-0541 org.eclipse.xtext.sdk
Eclipse Modeling Project EMF - Eclipse Modeling Framework Runtime and Tools 2.26.0.v20210506-1425 org.eclipse.emf
Eclipse Modeling Project EMF Ecore 2.24.0.v20210405-0628 org.eclipse.emf.ecore
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03746 seconds