Bug 356560

Summary: [1.7][compiler] Incorrect exception handling when using try-with-resources
Product: [Eclipse Project] JDT Reporter: Vincent PERICART <viper>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann, satyam.kandula, srikanth_sankaran, viper
Version: 3.8   
Target Milestone: 3.8 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Vincent PERICART CLA 2011-09-02 04:44:53 EDT
Build Identifier: I20110805-1200

The following snippet will compile without warning on JDK7.

    private static void closeThat(Closeable that) throws IOException {
        try (Closeable toClose = that) {
            // closes toClose
        }
    }

Though, on Eclipse, it will output a warning ("The declared exception IOException is not actually thrown...").

Removing the exception :

    private static void closeThat(Closeable that) {
        try (Closeable toClose = that) {
            // closes toClose
        }
    }

will pass the compiler check on Eclipse, but will fail to compile with the JDK7.
It is indeed translateable to : 

    private static void closeThat(Closeable that) {
        Closeable toClose = that;
        try {
           
        } finally {
            toClose.close(); // throws IOException
        }
    }


Reproducible: Always

Steps to Reproduce:
1. Input provided code in Eclipse Java editor
Comment 1 Olivier Thomann CLA 2011-09-02 10:54:36 EDT
This seems to be fixed in HEAD and 3.7 maintenance.
Could you please provide the org.eclipse.jdt.core bundle id ?
You can find it into Help>About Eclipse SDK>Installation Details>Plugins.
Comment 2 Olivier Thomann CLA 2011-09-09 09:23:58 EDT
Closing as WORKSFORME.
Satyam, if you can find the duplicate, you can close it as a dup.
Comment 3 Satyam Kandula CLA 2011-09-12 03:10:02 EDT
I am not able to reproduce even with the build of I20110802-2000.
Verified for 3.8M2 with build I20110911-2000