Bug 185743 - [introduce parameter object] introduces stack overflow on recursions
Summary: [introduce parameter object] introduces stack overflow on recursions
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Karsten Becker CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 185762 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-07 08:34 EDT by Benno Baumgartner CLA
Modified: 2007-06-06 12:24 EDT (History)
2 users (show)

See Also:
martinae: review+
markus.kell.r: review+


Attachments
Patch for recursion problems (28.27 KB, patch)
2007-05-09 10:31 EDT, Karsten Becker CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2007-05-07 08:34:07 EDT
I20070503-1400

Given:
package test;
public class E1 {
	public void countDown(int i) {
		if (i == 0) {
			System.out.println("bumm!");
			return;
		}
		
		System.out.println(i);
		countDown(--i);
	}
	
	public static void main(String[] args) {
		new E1().countDown(10);
	}
}

1. Select countDown
2. Introduce Parameter Object
3. Accept defaults
Is:
package test;
public class E1 {
	public void countDown(CountDownParameter parameterObject) {
		int i = parameterObject.i;
		if (i == 0) {
			System.out.println("bumm!");
			return;
		}
		
		System.out.println(i);
		countDown(parameterObject);
	}
	
	public static void main(String[] args) {
		new E1().countDown(new CountDownParameter(10));
	}
}
Same problem when writing
i= i - 1;
countDown(i);
Should:
 Not do that;-) I guess create a new parameter object for recursive call would be the easiest thing to do.
Comment 1 Karsten Becker CLA 2007-05-07 09:51:51 EDT
*** Bug 185762 has been marked as a duplicate of this bug. ***
Comment 2 Martin Aeschlimann CLA 2007-05-07 10:04:40 EDT
185762 is more than a duplicate of this bug:
The parameter can only used as is for recursive calls when:
- none of the values have changed
- all parameters are passed in the correct order
Comment 3 Karsten Becker CLA 2007-05-07 10:06:47 EDT
But the solution is the same ;)
Create a new Parameter Object for every recursive call.
Comment 4 Karsten Becker CLA 2007-05-09 10:31:18 EDT
Created attachment 66477 [details]
Patch for recursion problems

Only passes parameterObjects if all parameters have been inlined and are in same order.
Comment 5 Martin Aeschlimann CLA 2007-05-09 11:54:34 EDT
patch is good. I don't like the no-op changes at the end, but apart from that its good. Markus you should have a look at the changes to ChangeSignatureRefactoring.
Comment 6 Markus Keller CLA 2007-05-10 09:10:06 EDT
Improved loop in createChangeManager(..) by only storing non-declaration updates in an ArrayList.

Released to HEAD with a few cosmetics.
Comment 7 Benno Baumgartner CLA 2007-05-16 12:05:20 EDT
verified in I20070516-0010