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

Bug 388724

Summary: [surround with try/catch][quick fix] Multi-Catch QuickFix creates compiler error
Product: [Eclipse Project] JDT Reporter: Thomas Schindl <tom.schindl>
Component: UIAssignee: Samrat Dhillon <samrat.dhillon>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, gabor.liptak, manju656, markus.kell.r, samrat.dhillon
Version: 4.2Keywords: helpwanted
Target Milestone: 4.4 M3Flags: manju656: review-
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 478714, 478715    
Attachments:
Description Flags
patch for this bug
none
test for the patch
none
A video, which shows, that the bug still exists in Eclipse Mars. none

Description Thomas Schindl CLA 2012-09-04 04:34:57 EDT
This somehow looks like #348860 which should be fixed since a long time but I see this on 4.2.0

----8<----
package test;

import java.io.IOException;
import java.net.MalformedURLException;

public class TestException {
	private static void call() throws MalformedURLException, IOException {
		
	}
	
	public static void main(String[] args) {
		call();
	}

}
----8<----

when executing the multi-catch quickfix it creates code like this:

----8<----
package test;

import java.io.IOException;
import java.net.MalformedURLException;

public class TestException {
	private static void call() throws MalformedURLException, IOException {
		
	}
	
	public static void main(String[] args) {
		try {
			call();
		} catch (MalformedURLException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
----8<----
Comment 1 Markus Keller CLA 2012-09-04 07:07:16 EDT
Bug 348860 was about adding a quick fix to remove redundant catch clauses.

This bug is about a bug in the implementation of the surround with try-catch quick fix.
Comment 2 Samrat Dhillon CLA 2012-09-18 18:49:18 EDT
Created attachment 221222 [details]
patch for this bug

Proposing a patch for this defect. The intention of the modification is to filter down the list of exceptions so that if a super class of an exception is already present in the list, then the super class is used in the catch block and the subclass is removed from the list. 

Note that a similar fix is required for "Add exception to existing catch clause" proposal/quick fix.
Comment 3 Samrat Dhillon CLA 2013-10-14 13:53:56 EDT
Created attachment 236463 [details]
test for the patch

Adding tests for the patch submitted earlier. 
This contribution complies with http://www.eclipse.org/legal/CoO.php
Comment 4 Martin Mathew CLA 2013-10-17 08:20:11 EDT
The provided fix is too complicated. I have accepted the testcases. Fixed "Add exception to existing catch clause" also. Have a look at the released fix.

Released the fix as: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=794af31895de019e6dee502e0d1f0ba337c03cdd
Released the tests as: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=40af1211b9a2b7e7e9a8c6da73ab7be6b24f07a3
Comment 5 Gábor Lipták CLA 2015-09-18 03:07:45 EDT
This is still an issue with Eclipse 4.5.0. See the attached video. Please reopen the ticket.
Comment 6 Gábor Lipták CLA 2015-09-18 03:09:18 EDT
Created attachment 256663 [details]
A video, which shows, that the bug still exists in Eclipse Mars.
Comment 7 Gábor Lipták CLA 2015-09-18 03:10:30 EDT
Sorry, the attachment is an mp4. I made a mistake during renaming it.
Comment 8 Dani Megert CLA 2015-09-30 04:39:58 EDT
(In reply to Gábor Lipták from comment #5)
> This is still an issue with Eclipse 4.5.0. See the attached video. Please
> reopen the ticket.

For better bookkeeping please file a new bug that depends on this one. Thanks.
Comment 9 Gábor Lipták CLA 2015-09-30 09:36:18 EDT
(In reply to Dani Megert from comment #8)
> (In reply to Gábor Lipták from comment #5)
> > This is still an issue with Eclipse 4.5.0. See the attached video. Please
> > reopen the ticket.
> 
> For better bookkeeping please file a new bug that depends on this one.
> Thanks.

Created Bug 478715.