Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365101 - [xtend] validate that the same exception isn't caught multiple times
Summary: [xtend] validate that the same exception isn't caught multiple times
Status: RESOLVED WORKSFORME
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-29 11:55 EST by Moritz Eysholdt CLA
Modified: 2016-08-24 08:29 EDT (History)
2 users (show)

See Also:
sven.efftinge: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Moritz Eysholdt CLA 2011-11-29 11:55:40 EST
Example
----
class foo  {
	def bar() {
		try { new File("foo").canonicalPath  } catch(IOException o) {  "bar" } catch(IOException o) {  "bar" }
	}
}
----

Compiles to 

-----
public class foo {
  public String bar() {
    String _xtrycatchfinallyexpression = null;
    try {
      File _file = new File("foo");
      String _canonicalPath = _file.getCanonicalPath();
      _xtrycatchfinallyexpression = _canonicalPath;
    } catch (final IOException o) {
      _xtrycatchfinallyexpression = "bar";
    } catch (final IOException o_1) {
      _xtrycatchfinallyexpression = "bar";
    }
    return _xtrycatchfinallyexpression;
  }
}
----

The Java code doesn't compile due to the error "Unreachable catch block for IOException. It is already handled by the catch block for IOException".

I'd expect to see the same validation error in Xtend.
Comment 1 Moritz Eysholdt CLA 2011-11-29 12:03:05 EST
The same applies of a supertype of an exception is caught before its subtype:

---
try { new File("foo").canonicalPath  } catch(Exception o) {  "bar" } catch(IOException o) {  "bar" }
---
Comment 2 Christian Dietrich CLA 2016-08-24 08:29:57 EDT
Our Deady code detection catches this case menawhile