Bug 129453

Summary: [quick fix] add unimplemented methods should add compatible throws clause
Product: [Eclipse Project] JDT Reporter: Mike Fikes <mike.fikes>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P5 CC: eclipse, konigsberg, markus.kell.r, srikanth_sankaran
Version: 3.2Keywords: helpwanted
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Mike Fikes CLA 2006-02-25 10:35:15 EST
If you have two interfaces, each with a method with the same name, return type, and arguments, but differing throws clauses, and you are working with a class that implements both interfaces, the Quickfix to 'add unimplemented methods' will add a method that overrides the method from the first interface, including the throws clause defined in that interface. This throws clause may, in fact not be compatible with the throws clause in the second interface (and may need to have one or more exceptions removed, or the declaration of common subclasses in order to make it compatible). This enhancement request is to have that done automatically in order to avoid the immediate compilation error that results after the Quickfix is done.

A specific example:

public interface First {
    void foo() throws IOException, ClassNotFoundException;
}

public interface Second {
    void foo() throws FileNotFoundException;
}

Quick fix will result in:

public class Bar implements First, Second {
    public void foo() throws IOException, ClassNotFoundException {        
    }
}

but, this ticket asks that it result in:

public class Bar implements First, Second {
    public void foo() throws FileNotFoundException {        
    }
}

not because it is the signature from Second, but because it declares execptions compatible with both interfaces.
Comment 1 Eclipse Webmaster CLA 2007-07-29 09:19:07 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991
Comment 2 Chris West (Faux) CLA 2010-04-04 17:41:55 EDT
"Me too!"  I20100129-1300 (3.6M something, x86 linux).

Stolen from Java Puzzlers (Bloch, Gafter) #37, where they say that the exceptions should be an intersection of all of the overloads' thrown exceptions, but they cite JLS 15.12.2.5 which doesn't seem to be relevant.

Compiler seems to agree, though.
Comment 3 Markus Keller CLA 2010-04-06 10:45:05 EDT
*** Bug 135097 has been marked as a duplicate of this bug. ***
Comment 4 Srikanth Sankaran CLA 2012-06-11 02:23:27 EDT
Me too - While testing some java 8 code snippets ran into this with 3.8 RC3