Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352445

Summary: [1.7][extract method][extract constant][extract local] Extract local variable should not be available inside the resource specification of try-with-resources
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: daniel_megert, deepakazad, markus.kell.r, raksha.vasisht
Version: 3.7Flags: daniel_megert: review+
Target Milestone: 3.7.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
proposed fix + tests none

Description Ayushman Jain CLA 2011-07-19 07:54:58 EDT
BETA_JAVA7

class Test{
public static void main(String[] args) throws IOException {
	try (FileInputStream fis = null) {
        }
}
}

Select FileInputStream fis = null > refactor> extract local variable is proposed. Choosing it gives some garbage code.
Comment 1 Ayushman Jain CLA 2011-07-19 08:21:47 EDT
Also the same happens with the "Extract constant" refactoring on 
class Test{
public static void main(String[] args) throws IOException {
    try (FileInputStream fis = new FileInputStream("")) {
        }
}
}

(select the whole of FileInputStream fis = new FileInputStream("") ).

IMHO, these 2 refactorings should be disabled.
Comment 2 Dani Megert CLA 2011-07-20 04:47:00 EDT
Confirmed. Deepak, please take a look.
Comment 3 Deepak Azad CLA 2011-07-22 01:45:30 EDT
Adding extract method to the list.
Comment 4 Deepak Azad CLA 2011-07-25 05:18:23 EDT
Created attachment 200259 [details]
proposed fix + tests

The patch contains 3 new strings to explain why a refactoring is not enabled. Dani is it possible to add these now ? (The patch also has the fix for Bug 352445)
Comment 5 Dani Megert CLA 2011-07-26 06:11:36 EDT
(In reply to comment #4)
> Created attachment 200259 [details] [diff]
> proposed fix + tests
> 
> The patch contains 3 new strings to explain why a refactoring is not enabled.
> Dani is it possible to add these now ?
Yes.

> (The patch also has the fix for Bug
> 352445)
You probably meant "bug 352448".

NOTE: You forgot to add the legal blurb to
  ConstantChecks.java
  ExtractMethodAnalyzer.java
Comment 6 Deepak Azad CLA 2011-07-26 07:28:36 EDT
(In reply to comment #5)
> > (The patch also has the fix for Bug
> > 352445)
> You probably meant "bug 352448".
Yes :)


(In reply to comment #4)
> Created attachment 200259 [details]
> proposed fix + tests
Committed to BETA_JAVA7 (after addition of the missing legal blurbs).
Comment 7 Raksha Vasisht CLA 2011-08-02 04:52:27 EDT
Verified for Juno M1 with 4.2 build I20110729-0200.
Comment 8 Raksha Vasisht CLA 2011-08-03 06:13:54 EDT
.