Closed parrt closed 9 years ago
I can't seem to reproduce this error with that grammar. The issue is that a reference to an undefined rule leaves an empty ATNFactory.Handle
for rule element
in alternative
of ATNBuilder.g
:
alternative returns [ATNFactory.Handle p] :
...
^(ALT elementOptions? (e=element {els.add($e.p);})+) {$p = factory.alt(els);}
The call to alt
eventually reaches the following line in elemList
:
else tr.target = els.get(i+1).left;
The els.get(i+1)
is likely returning null which causes the problem.
This is almost certainly a problem with ANTLR itself because both paths lead to the same point in Tool.processNonCombinedGrammar()
that should be checking for syntactic and semantic errors before creating an ATN.
Was using latest HEAD not 1.6. That grammar with 1.6 gives an error. I changed fieldnme to fieldname or was it fielddfname and saved then "test rule term".
field : {!isDateField()}? string '.' fieldname ;
null
java.lang.NullPointerException
at org.antlr.intellij.plugin.preview.PreviewPanel.ensureStartRuleExists(PreviewPanel.java:145)
at org.antlr.intellij.plugin.preview.PreviewPanel.grammarFileSaved(PreviewPanel.java:126)
at org.antlr.intellij.plugin.ANTLRv4PluginController.grammarFileSavedEvent(ANTLRv4PluginController.java:262)
at org.antlr.intellij.plugin.ANTLRv4PluginController$MyVirtualFileAdapter.contentsChanged(ANTLRv4PluginController.java:526)
at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.util.EventDispatcher.dispatch(EventDispatcher.java:88)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:34)
at com.intellij.util.EventDispatcher$1.invoke(EventDispatcher.java:68)
at com.sun.proxy.$Proxy17.contentsChanged(Unknown Source)
at com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter.fireAfter(BulkVirtualFileListenerAdapter.java:65)
at com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter.after(BulkVirtualFileListenerAdapter.java:56)
at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:114)
at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:315)
at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:302)
at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:287)
at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:41)
at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:177)
at com.sun.proxy.$Proxy18.after(Unknown Source)
at com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl$5.close(PersistentFSImpl.java:649)
at com.intellij.openapi.fileEditor.impl.LoadTextUtil.write(LoadTextUtil.java:259)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl$4.run(FileDocumentManagerImpl.java:421)
at com.intellij.pom.core.impl.PomModelImpl.guardPsiModificationsIn(PomModelImpl.java:354)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.a(FileDocumentManagerImpl.java:408)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.a(FileDocumentManagerImpl.java:382)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:303)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:282)
at com.intellij.openapi.application.impl.ApplicationImpl.saveAll(ApplicationImpl.java:1449)
at com.intellij.ide.actions.SaveAllAction.actionPerformed(SaveAllAction.java:26)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:614)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:663)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:513)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:211)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:546)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
which is
Rule rule = previewState.g.getRule(previewState.startRuleName);
I think it has to do with the fact that the interp/preview seems to work even with bad rule ref:
field : {!isDateField()}? string '.' fieldnme ;
Yep, won't preview if I load with fielnme misspelled but if i fix and test then misspell it still works. Could be source of issue. Stuff is out of sync with cached ATN.
1.7 seems to fix this (could be fix in antlr 4.5.1).
and again:
FROM: