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

Bug 343096

Summary: [xtend2] StackOverflowError in recursive function
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.0.0Flags: sven.efftinge: indigo+
Target Milestone: SR2   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-04-18 03:49:38 EDT
With the following Xtend2 snippet:

	<T> test() {
		[T t|switch t {
			case t:test
		}]
	}

I get a StackOverflowError from the builder (or the reconciler):

java.lang.StackOverflowError
	at org.eclipse.xtext.common.types.impl.JvmParameterizedTypeReferenceImpl.getArguments(JvmParameterizedTypeReferenceImpl.java:92)
	at org.eclipse.xtext.common.types.impl.JvmParameterizedTypeReferenceImpl.eGet(JvmParameterizedTypeReferenceImpl.java:170)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1013)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjectImpl.java:1005)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:409)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:222)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:188)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:488)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:1)
	at org.eclipse.emf.common.util.ArrayDelegatingEList.addUnique(ArrayDelegatingEList.java:395)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
	at org.eclipse.emf.ecore.util.EContentAdapter.addAdapter(EContentAdapter.java:352)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:225)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:188)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:488)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:1)
	at org.eclipse.emf.common.util.ArrayDelegatingEList.addUnique(ArrayDelegatingEList.java:395)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
	at org.eclipse.emf.ecore.util.EContentAdapter.addAdapter(EContentAdapter.java:352)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:225)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:188)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:488)
	at org.eclipse.emf.ecore.impl.MinimalEObjectImpl$1.didAdd(MinimalEObjectImpl.java:1)
	at org.eclipse.emf.common.util.ArrayDelegatingEList.addUnique(ArrayDelegatingEList.java:395)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
	at org.eclipse.emf.ecore.util.EContentAdapter.addAdapter(EContentAdapter.java:352)
	at org.eclipse.emf.ecore.util.EContentAdapter.setTarget(EContentAdapter.java:225)

By adding another case to the switch the error goes away:

	<T> test() {
		[T a|switch a {
			case null:null
			case a:test
		}]
	}
Comment 1 Sebastian Zarnekow CLA 2011-04-25 14:30:26 EDT
This one is tricky. The return type of test is effectivly
Function1<T, [return type of test]>. It seems hard to track the origin of a type argument / type reference to detect this kind of recursion but it should be possible to use EAdapters that point to the origin of a type reference. This data could be used to identify that we run into an recursively nested structure. Maybe somebody has another idea?
Comment 2 Sebastian Zarnekow CLA 2011-04-25 14:38:28 EDT
It should be simpler to avoid copying proxies during the return type inference. Since we would run into recursive proxy resolution if the proxy is resolved prior to setting the value in its container, we could use the recursion detection from Xtend2Resource#getEObject
Comment 3 Sebastian Zarnekow CLA 2011-05-04 06:11:30 EDT
Preliminary scheduled for 2.0RC1
Comment 4 Sven Efftinge CLA 2011-05-04 09:59:05 EDT
postponed to SR1
Comment 5 Knut Wannheden CLA 2011-09-19 14:46:05 EDT
Just tried this example again and it can lead to all kinds of weird problems. Unfortunately the builder also doesn't get past a file with this content and of course also locks the file. So the user must in the end kill Eclipse and then on startup be fast and disable autobuild. Could this be the first Xtend virus? :-)
Comment 6 Sebastian Zarnekow CLA 2011-09-28 10:11:54 EDT
The StackOverflowError does no longer happen though you still get some strange error marker about dangling references but I bet this is better than a StackOverflow. Closed as fixed since the dangling references for erroneous are another topic.
Comment 7 Knut Wannheden CLA 2011-09-28 10:19:56 EDT
Excellent!
Comment 8 Karsten Thoms CLA 2017-09-19 17:49:45 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 9 Karsten Thoms CLA 2017-09-19 18:00:42 EDT
Closing all bugs that were set to RESOLVED before Neon.0