Project: JDT
Bug 132687 Extract method refactoring does not analyze execution flow properly
Reported: 2006-03-21 10:12:22 | Status: resolved fixed

When trying to use the extract method refactoring on the following codeblock I got an messagebox which told me "Selected statements contain a return statement but not all possible execution flows end in a return" public void foo(List list, Object constraint, int index) { Map m = new HashMap(); if (list instanceof List) { List f= (List) list; if (f.size() == -1) { if (m.isEmpty()) { // do sth } else { for (Iterator iter= m.keySet().iterator(); iter.hasNext();) { // do sth for (Iterator iterator = Collections.EMPTY_LIST.iterator(); iterator.hasNext();) { // do sth if (true == false) { // do sth return; } // do sth } } } } } } What I expected to get was the following: public void foo(List list, Object constraint, int index) { Map m = new HashMap(); if (list instanceof List) { List f= (List) list; doSth(f, m); } } private void doSth(List f, Map m) { if (f.size() == -1) { if (m.isEmpty()) { // do sth } else { for (Iterator iter= m.keySet().iterator(); iter.hasNext();) { // do sth for (Iterator iterator = Collections.EMPTY_LIST.iterator(); iterator.hasNext();) { // do sth if (true == false) { // do sth return; } // do sth } } } } }

Files changed in fix:
org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractMethodAnalyzer.java