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

Bug 352465

Summary: [1.7] Surround with try/multi-catch uses different variable names
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: trivial    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ayushman Jain CLA 2011-07-19 10:31:36 EDT
BETA_JAVA7

class Test{
public static void main(String[] args) throws IOException{
		boolean b = true;
                // selection start
		if (b)
		throw new FileNotFoundException();
		else throw new ClassNotFoundException();
		//selection end

		try {
			
		} catch (ClassNotFoundException e) {
			
		} catch (AssertionError e1) {
			
		}
}
}

Selecting from the if(b) to the throw new IOException statement and choosing Surround with> Try/multi catch gives the following output

try {
			if (b)
			throw new FileNotFoundException();
			else throw new ClassNotFoundException();
		} catch (ClassNotFoundException e2) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

Notice the use of e2 in catch expression and e inside catch body.

This works fine with surround with try/catch.
Comment 1 Deepak Azad CLA 2011-07-19 10:43:33 EDT
Good catch!

Fix to go in SurroundWithTryCatchRefactoring line 282. (Replace 'varName' with 'name')
Comment 2 Deepak Azad CLA 2011-07-21 01:10:52 EDT
Fixed in BETA_JAVA7
Comment 3 Dani Megert CLA 2011-08-03 06:15:53 EDT
Verified in I20110729-1200 and M20110729-1400.