History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-11844
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Normal Normal
Assignee: Alexey Kudravtsev
Reporter: Keith Lea
Votes: 3
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

"Extract method" produces bad code sometimes when try/finally block present

Created: 08 May 05 10:00   Updated: Tuesday 09:29
Component/s: Refactoring
Fix Version/s: Diana Next EAP

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
Issue Links:
Duplicate
 
This issue is duplicated by:
IDEA-17295 Extract Method creates invalid code Resolved
IDEADEV-24692 Bogus parameter offered during extrac... Normal Resolved

Build: 3,326
Fixed in build: 8,745
Severity: Medium


 Description  « Hide
Given this code:

class Tester {
String x() {
String o = "";
// selection start
String s;
try { s = o; } finally {

}
return s;
// selection end
}
}

Select the specified text and choose Extract Method. IDEA shows "String s" as one of the parameters to the method even though it is defined in the extracted code. Click OK, IDEA produces this code which contains two errors:

class Tester {
String x() { String o = ""; return extracted(o, s); }

private String extracted(String o, String s) {
String s;
try { s = o; } } finally {

}
return s;
}
}



 All   Comments   Work Log   Change History      Sort Order:
Bas Leijdekkers - 21 Jul 05 18:21
another example:

class Extract {
void test() {
try {
final FileInputStream fileInputStream = new FileInputStream("test");
try { fileInputStream.read(); } finally { fileInputStream.close(); }
} catch(IOException e) { e.printStackTrace(); }
}
}

When extracting the enter contents of the method, IDEA suggests a method parameter for the IOException.


Alexander Chernikov - 13 Nov 06 16:24
Still repeats in 6101. E.g.:
int opera() {
        int i = 0;
        // selection starts next line
        int k;
        if (true) k = i;
        return k;
        // selection ends previous line
    }

The essential thing to reproduce is that initialization of a variable (k) is in the code that formally can be not executed ("try", "if" statements). If we change "int k" to "int k=0", refactoring works correctly.