Bug 491929 - StackOverflowError when using many else-if-statements
Summary: StackOverflowError when using many else-if-statements
Status: UNCONFIRMED
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.9.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-18 12:30 EDT by Dietmar Stoll CLA
Modified: 2016-04-20 07:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dietmar Stoll CLA 2016-04-18 12:30:23 EDT
A Xtend file with lots of else-if-statements leads to a stack overflow. (A generator in an existing project created the Xtend file with about 500 else-if-statements.)

Steps to reproduce:
- Create an Xtend file with a method containing, for instance, 500 "else if" statements in a text editor
def void multiElseIf() {
if (true) {	return 	} 
		else if (true) { return } 
		else if (true) { return } 
    // ... x500
	}    

- open the file in the Xtend editor
Expected: File opens without errors
Actual:  java.lang.StackOverflowError

A workaround would be to use Xtend case statements. The Eclipse Java editor handles multiple else-if-statements in Java of the same quantity without errors Manual Java code:
		if (true) { return; }
		else if (true) { return;}
		else if (true) { return;}
		// ...

The generated Java code from the Xtend snippet looks like this:
    if (true) {
      return;
    } else {
      if (true) {
        return;
      } else {
...
Comment 1 Sven Efftinge CLA 2016-04-19 02:00:57 EDT
That's a guard we added to help people not generating xtend code :-)
Comment 2 Dietmar Stoll CLA 2016-04-20 07:19:05 EDT
Yes, maybe because of the nesting in the generated Java code vs. non-nesting in the handwritten Java code. Luckily, the guard is not active when we use Xtend case statements ;-)