Project: JDT
Bug 213519 [extract method] Missing return value, while extracting code out of a loop
Reported: 2007-12-19 14:53:37 | Status: verified fixed

Build ID: M20071023-1652 Steps To Reproduce: There is a curious behavior of extract method when extracting a code snippet out of a loop after a for(Class var : Colection) construction. More information: Sample Code: ------------------------------------ Line of code to extract: list.add(a++); ------------------------------------ Code where Extract Method returns an int as return value of the extracted snippet: Good Code: ------------------------------------ ArrayList<Integer> list = new ArrayList<Integer>(); int a = 0; for (int c = 0; c < 10; c++) { list.add(a++); } System.out.println(list.toString()); ------------------------------------ Method signature: private static int someMethodName(ArrayList<Integer> list,int a) After adding a for loop in front of the counting loop, the Extract Method return value is void. Bad Code: ------------------------------------ ArrayList<Integer> list = new ArrayList<Integer>(); for (Integer var: list) {} int a = 0; for (int c = 0; c < 10; c++) { list.add(a++); } System.out.println(list.toString()); ------------------------------------ Method signature: private static void someMethodName(ArrayList<Integer> list,int a)

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test729.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test730.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test731.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test732.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test729.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test730.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test731.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test732.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/flow/InputFlowAnalyzer.java