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

Bug 352629

Summary: [1.7][quick fix] Quick-fix to add exceptions to existing list leaves code in error state
Product: [Eclipse Project] JDT Reporter: Michael Rennie <Michael_Rennie>
Component: UIAssignee: Deepak Azad <deepakazad>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Michael Rennie CLA 2011-07-20 12:35:53 EDT
Consider the following snippet:

package a;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class MultiCatch {
	public static void main(String[] args) {
		File file = new File("");
		try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
			System.err.println("reading...");
		}
		catch(NullPointerException | IllegalArgumentException ex){}
	}
}

Steps:

1. once pasted there should be 2 errors about un-caught exceptions
2. quick fix the FileNotFoundException to add the exceptions to the existing list of exceptions
3. save

Notice at this point your code has an error about FileNotFoundException being covered by IOException. Perhaps the quick-fix could be enhanced to detect this scenario (redundant exceptions) and avoid the 'already caught error'?
Comment 1 Deepak Azad CLA 2011-07-20 23:28:11 EDT
See the reasoning in bug 350713 comment 2.
Comment 2 Dani Megert CLA 2011-07-21 03:26:02 EDT
I agree in general, but we should be smarter on the produced code i.e. we should offer a 'Use separate catch blocks' Quick Fix. The Quick Assist is hard to detect in the current case: one either has to select parts of the 'catch' statement or invoke Ctrl+1 twice.
Comment 3 Deepak Azad CLA 2011-07-21 03:55:40 EDT
(In reply to comment #2)
> I agree in general, but we should be smarter on the produced code i.e. we
> should offer a 'Use separate catch blocks' Quick Fix. 
That is Bug 352477.
Comment 4 Dani Megert CLA 2011-07-21 03:56:47 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > I agree in general, but we should be smarter on the produced code i.e. we
> > should offer a 'Use separate catch blocks' Quick Fix. 
> That is Bug 352477.

:-)