Parsing an empty file produces NPEs
I am currently writing templates in SDF3 to enable Pretty Printing and Code Completion.
In an example MiniJava file if I delete everything (or if I make a new file) I get an error message:" ‘MiniJava ParserScheduler for example.mjv’ has encountered a problem. An internal error occurred during: “MiniJava ParserScheduler for example.mjv”.", with further explanation: java.lang.NullPointerException
If the file contains anything, then nothing happens. I am not sure whether is it my mistake, or an issue with a Spoofax.
Submitted on 9 October 2013 at 03:27
Issue Log
This is most likely a bug in Spoofax. Can you get any more information in the Eclipse error log?
No, error log just repeat that, with explanation:
An internal error occurred during: “MiniJava ParserScheduler for example.mjv”.
java.lang.NullPointerException
This happens if your grammar does not include any definition of
LAYOUT
. You can check this ininclude/<YourLang>.def
. If there is no definition of layout, you probably forgot an import.However, in this case the build should not produce a parse table.
I checked
include/MiniJava.def
and there is aLAYOUT
definition in it. Also, parse table is generated as well.
Apparently, this is a bug that appears on Windows systems, when you have an empty (or almost empty) file. Paste a complete program into your editor, and it should vanish.
Yes, even if there is only one space or a new line, there is no error. And you are right, I am using Eclipse for Windows.
May be related to https://yellowgrass.org/issue/Spoofax/697
Can confirm that it’s related to empty files and vanishes once a full program is parsed. It’s not limited to Windows though, I’m running into the issue on Linux as well.
Yes, the NPE is caused by the AST for that editor being null somewhere, because no valid AST has been constructed yet. Once a valid AST has been constructed, it stops producing NPEs.
I get this now also on Mac OS. Either we did not recognise this before, because most of our grammars parse empty files, or this was introduced by a recent change. Any ideas?
This bug does not occur in stable. It also occurs in nightly, if you use only SDF2 grammars w/o any extra rules generated from SDF3.
It looks like the outline view system needs to defend against a
null
ast. This is a corresponding stack trace:java.lang.NullPointerException at org.strategoxt.imp.runtime.services.views.outline.SpoofaxOutlinePage.update(SpoofaxOutlinePage.java:89) at org.strategoxt.imp.runtime.services.views.outline.SpoofaxOutlinePage.update(SpoofaxOutlinePage.java:72) at org.eclipse.imp.editor.ParserScheduler.notifyModelListeners(ParserScheduler.java:136) at org.eclipse.imp.editor.ParserScheduler.run(ParserScheduler.java:95) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Assigning this to Oskar for now.
Log in to post comments