Community
Participate
Working Groups
Hi, the editor for my grammar *sometimes* complains about dangling references when there should be none. There are no errors in the error log, nor is there any output on the console. Here's what I observe: * The file itself appears to be correct. The Xtext builder does not show any errors in the problem view when validating the model. * When I open the editor, there are no markers either. * When I now edit the file right after the problematic part, re-validation within the editor typically fails with the above mentioned dangling reference error. * When I save the file, the builder still does not complain about any errors. The marker in the editor, however, remains. * Now close and reopen the editor => Marker is gone. * Content assist at the problematic part works fine when opening a fresh editor. * When the editor shows that marker, however, content assist yields the following error. That, too, is caused by an EObject not being contained in a resource. java.lang.NullPointerException at org.eclipse.xtext.resource.IGlobalServiceProvider$ResourceServiceProviderImpl.findService(IGlobalServiceProvider.java:59) at org.eclipse.xtext.ui.editor.hover.DispatchingEObjectTextHover.getHoverInfo(DispatchingEObjectTextHover.java:31) at org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal.getAdditionalProposalInfo(ConfigurableCompletionProposal.java:486) at org.eclipse.jface.text.contentassist.AdditionalInfoController$3.run(AdditionalInfoController.java:106) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) Since the Xtext builder always validates the models correctly I assume that this is not a bug in my grammar or my code, but it lies somewhere in the editor dirty state handling. I cannot disclose the grammar, but I can help debugging if you need more clues. Cheers, Achim
So you have these errors when editing the Xtext grammar for your language? What kind of references do you have to other grammars and Ecore models?
No, these errors occur in the editor for my language, not the grammar editor. There are no references to other grammars, but I use my own Ecore model and do not derive the metamodel from the grammar.
could you please debug and tell us what the EObject without the resource looks like?
Created attachment 198804 [details] Object state in debugger This screenshot shows the EObject (ModuleImpl) without a resource. The object itself and all its children are perfectly ok, their data is correct, all references are set and valid. It simply has no eResource, which it should have because ModuleImpl is the root of the object graph. IIRC I saw in the debugger that the resource has been unloaded at some point during re-parsing of the file and that the re-parsed object tree has been loaded correctly. It seems that the linker did not notice that new object graph and still uses the old one.
Are you doing any kind of modifications? Maybe you should also check, whether a cross reference is used for a containment reference.
(In reply to comment #5) > Are you doing any kind of modifications? No, I do not modify the model in any way. Neither the top-level Module object, nor any other model element. However, during validation I do create some new objects. But I checked again that these objects do not interfere with the objects created by Xtext, especially that they do not pull an EObject out of its eContainer. > Maybe you should also check, whether a cross reference is used for a > containment reference. I checked, but everything looks ok. A Module can reference other Modules, which is declared as a cross-reference in the grammar and defined as a non-containment reference in the Ecore model. Any other hints how I can debug this?
My bad. I mentioned that I created new EObjects during validation. These EObjects reference some of my model EObjects parsed by Xtext. I had good intentions of caching these newly created objects. After re-parsing in the editor, the model EObjects referenced by my EObjects got unloaded from the resource. When I then hand out my cached objects, Xtext picks up the unloaded objects and correctly yields the "dangling reference" error. Now I no longer cache these objects and everything works fine. Sorry to bother you. I'll try to file a *real* bug next time ;-)