Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350562 - Dangling references in editor, but not in builder
Summary: Dangling references in editor, but not in builder
Status: CLOSED INVALID
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-28 07:48 EDT by Achim Demelt CLA
Modified: 2011-06-30 02:53 EDT (History)
1 user (show)

See Also:


Attachments
Object state in debugger (61.67 KB, image/png)
2011-06-29 05:09 EDT, Achim Demelt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Achim Demelt CLA 2011-06-28 07:48:11 EDT
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
Comment 1 Sven Efftinge CLA 2011-06-28 08:09:27 EDT
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?
Comment 2 Achim Demelt CLA 2011-06-28 14:52:57 EDT
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.
Comment 3 Sven Efftinge CLA 2011-06-29 03:54:51 EDT
could you please debug and tell us what the EObject without the resource looks like?
Comment 4 Achim Demelt CLA 2011-06-29 05:09:21 EDT
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.
Comment 5 Sven Efftinge CLA 2011-06-29 07:38:25 EDT
Are you doing any kind of modifications?
Maybe you should also check, whether a cross reference is used for a containment reference.
Comment 6 Achim Demelt CLA 2011-06-29 07:57:33 EDT
(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?
Comment 7 Achim Demelt CLA 2011-06-30 02:53:21 EDT
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 ;-)