Project: JDT
Bug 97413 [extract method] missing return type when code can throw exception
Reported: 2005-05-31 06:10:09 | Status: verified fixed

I20050527-1300 Extracting code that can return a value and ends with throwing an exception results in a new method with no return type - and therefore compile errors. No other errors or exceptions. Before: class Foo { int bar(int bar) { if (bar > 0) return bar - 1; throw new IllegalArgumentException(); } } After: class Foo { int bar(int bar) { foo(bar); } private void foo(int bar) { if (bar > 0) return bar - 1; throw new IllegalArgumentException(); } } Swapping the return and the throw statements works. Before: class Foo { int bar(int bar) { if (bar > 0) throw new IllegalArgumentException(); return bar - 1; } } After: class Foo { int bar(int bar) { return foo(bar); } private int foo(int bar) { if (bar > 0) throw new IllegalArgumentException(); return bar - 1; } }

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test733.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_in/A_test734.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test733.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/return_out/A_test734.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/FlowInfo.java