Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326937

Summary: IllegalArgumentException resulted in Outline View
Product: [Modeling] TMF Reporter: Samantha Chan <chanskw>
Component: XtextAssignee: Jan Koehnlein <jan>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jan, sebastian.zarnekow, sven.efftinge, tmf.xtext-inbox
Version: 1.0.1Flags: jan: helios+
sebastian.zarnekow: indigo+
Target Milestone: M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Samantha Chan CLA 2010-10-04 11:41:55 EDT
Setup / Observations:

1)  I am using the default implementation of the outline page.  However, I have implemented the ISemanticModelTransformer, where I alter the structure of the outline view.

2)  I have to turn on the "Link Editor" action in the outline view to reproduce this problem.

3)  The problem seems to be related with the transformer.  If I comment out all the code from my transformer, I do not get these exceptions.

4)  The issue is this... When I comment out some elements the editor, the structure of the AST / outline view has changed.  When the IContentOutlineNodeForTextSelectionFinder tries to traverse the elements, the URI used and the element does not match.  The URI seems to be stale, and causes the wrong EObject type to be used during the traverse operation, and resulted in this exception.

5)  Another observation is that in my transfer, I have actually filtered out the "clauses" element from the tree.  And it seems to be that these filtered out elements are causing exceptions.


java.lang.IllegalArgumentException: The feature 'clauses' is not a valid feature
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eStructuralFeature(BasicEObjectImpl.java:739)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eObjectForURIFragmentSegment(BasicEObjectImpl.java:533)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:782)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:758)
	at org.eclipse.xtext.resource.XtextResource.access$1(XtextResource.java:1)
	at org.eclipse.xtext.resource.XtextResource$1.getEObject(XtextResource.java:92)
	at org.eclipse.xtext.resource.DefaultFragmentProvider.getEObject(DefaultFragmentProvider.java:26)
	at org.eclipse.xtext.resource.XtextResource.getEObject(XtextResource.java:260)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:123)
	at org.eclipse.xtext.resource.EObjectHandleImpl$ResourceAccess.exec(EObjectHandleImpl.java:55)
	at org.eclipse.xtext.resource.EObjectHandleImpl$ResourceAccess.exec(EObjectHandleImpl.java:1)
	at org.eclipse.xtext.util.concurrent.IStateAccess$AbstractImpl.readOnly(IStateAccess.java:40)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:70)
	at org.eclipse.xtext.resource.EObjectHandleImpl.readOnly(EObjectHandleImpl.java:39)
	at org.eclipse.xtext.ui.editor.outline.ContentOutlineNode.processHandleForChildren(ContentOutlineNode.java:126)
	at org.eclipse.xtext.ui.editor.outline.ContentOutlineNode.computeChildren(ContentOutlineNode.java:121)
	at org.eclipse.xtext.ui.editor.outline.ContentOutlineNode.getChildren(ContentOutlineNode.java:104)
	at org.eclipse.xtext.ui.editor.outline.ContentOutlineNode.getChildrenAsArray(ContentOutlineNode.java:136)
	at org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeForTextSelectionFinder$Default.traverse(IContentOutlineNodeForTextSelectionFinder.java:48)
	at org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeForTextSelectionFinder$Default.traverse(IContentOutlineNodeForTextSelectionFinder.java:49)
	at org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeForTextSelectionFinder$Default.traverse(IContentOutlineNodeForTextSelectionFinder.java:49)
	at org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeForTextSelectionFinder$Default.traverse(IContentOutlineNodeForTextSelectionFinder.java:49)
	at org.eclipse.xtext.ui.editor.outline.IContentOutlineNodeForTextSelectionFinder$Default.traverse(IContentOutlineNodeForTextSelectionFinder.java:49)
	at org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage.synchronizeOutlinePage(XtextContentOutlinePage.java:331)
	at org.eclipse.xtext.ui.editor.outline.linking.EditorSelectionChangedListener.selectionChanged(EditorSelectionChangedListener.java:31)
	at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2745)
	at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2693)
	at org.eclipse.jface.text.TextViewer$5.run(TextViewer.java:2672)
	at org.eclipse.swt.widgets.Display.timerProc(Display.java:4106)
	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2229)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3159)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:600)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Comment 1 Sebastian Zarnekow CLA 2010-10-04 14:42:59 EDT
We have to investigate whether the new outline infrastructure suffers from the same issue.
Comment 2 Jan Koehnlein CLA 2010-10-07 09:33:13 EDT
Samantha,

could you post the transformer code? It would be very helpful to track down this bug.
Comment 3 Samantha Chan CLA 2010-10-07 13:48:41 EDT
This is the transformer code that causes problem. I commented out all of my transformer code except for this... and I will get into exception.

Just to give you some background:

CompositeDef contains CompositeBody.
CompositeBody contains Clauses

I wanted to filter out the "CompositeBody" object from the outline view.  So, I removed filtered it out, and return the clauses as the children of CompositeDef.

	  public List<EObject> getChildren(CompositeDef typedef) {
		  List<EObject> children = super.getChildren(typedef);
		  List<EObject> filtered = new ArrayList<EObject>();
		  
		  Iterator<EObject> iter = children.iterator();
		  while(iter.hasNext())
		  {
			  EObject obj = iter.next();
			  if (obj instanceof CompositeBody)
			  {
				  List<EObject> caluses = super.getChildNodes(obj);
				  filtered.addAll(caluses);
			  }
		  }
		  return filtered;
	 }

I also noticed that if I commented out this code, the compositeDef does not have any children in the outline view.. and may possibly the reason why I do not get any exception.

Also, when the exception happens, the outline view is asking for the "Clauses" feature from a "Block"... which to mean means that there is something wrong with the parsing.
Comment 4 Jan Koehnlein CLA 2010-10-13 11:56:51 EDT
It looks like the problem is the following race condition:

The model has changed, but the outline has not been updated yet. When the link with editor mechanism tries to find the outline node to select, it resolves all children of the existing nodes. We are using URIs (in the EObjectHandles) to store the references to the semantic element of an outline node. The default URI fragment paths are fragile with respect to type change. I.e. if a new element of a different EClass takes the same place in the containment reference as the outline node's semantic element, we try to resolve children to an invalid parent. Consequently, we ask for a feature that does not exist on the parent element, causing this exception.

I am trying to write a test to reproduce this.
Comment 5 Jan Koehnlein CLA 2010-10-14 09:59:36 EDT
Pushed test and fix to Helios_Maintenance: Don't execute anything on EObjectHandleImpl's if the EClass changes. Please verify.

This error does not appear in MASTER due to outline redesign.
Comment 6 Samantha Chan CLA 2010-10-15 13:10:20 EDT
(In reply to comment #5)
> Pushed test and fix to Helios_Maintenance: Don't execute anything on
> EObjectHandleImpl's if the EClass changes. Please verify.
> 
> This error does not appear in MASTER due to outline redesign.

Thanks very much for the prompt response and fix. 
For planning purpose, when is XText 1.0.2 going to be released?
Comment 7 Sven Efftinge CLA 2010-10-17 04:02:07 EDT
At least with the Helios SR2 release (maybe earlier).
Comment 8 Karsten Thoms CLA 2017-09-19 17:30:29 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 9 Karsten Thoms CLA 2017-09-19 17:41:43 EDT
Closing all bugs that were set to RESOLVED before Neon.0