Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352629 - [1.7][quick fix] Quick-fix to add exceptions to existing list leaves code in error state
Summary: [1.7][quick fix] Quick-fix to add exceptions to existing list leaves code in ...
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Deepak Azad CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-20 12:35 EDT by Michael Rennie CLA
Modified: 2011-07-21 03:56 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.

:-)