Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348705 - [1.7][compiler] Improve error message for unhandled IOException generated due to compiler-generated close()
Summary: [1.7][compiler] Improve error message for unhandled IOException generated due...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-08 07:41 EDT by Ayushman Jain CLA
Modified: 2011-08-05 02:54 EDT (History)
4 users (show)

See Also:


Attachments
proposed fix v1.0 + regression tests (11.90 KB, patch)
2011-06-09 07:05 EDT, Ayushman Jain CLA
no flags Details | Diff
minor update (10.12 KB, patch)
2011-06-09 15:28 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-06-08 07:41:51 EDT
BETA_JAVA7

In the following scenario

 void foo(String name, boolean b) throws FileNotFoundException{ 
     ff = new FileInputStream(name);
     try (FileInputStream fis = ff) {     // see here
           throw new IllegalArgumentException();
     } catch (IllegalArgumentException e) {
		e.printStackTrace();
     }
	
      System.out.println("SUCCESS");
       
  } 

I get an unhandled IOException error message. This is confusing at first, since you'd think fis == ff is a harmless assignment which wouldnt throw IOException.Only on some deliberation it is clear to the user that this IOException corresponds to the close() call which is generated for the resource 'fis' by the compiler and thus it is necessary to handle the IOException.

We should perhaps make it clearer by changing the error message to explain the IOException.
Comment 1 Srikanth Sankaran CLA 2011-06-08 23:37:50 EDT
Yes, agree that state of affairs today can be confounding and
needs improvement.
Comment 2 Ayushman Jain CLA 2011-06-09 07:05:22 EDT
Created attachment 197680 [details]
proposed fix v1.0 + regression tests

Added a new error message "Unhandled exception type {0}, caused due to auto close of resource {1}" for exceptions raised ONLY during the auto close of a resource. Note that if the resource is explicitly closed inside the try block, we will report the old "Unhandled exception type {0}" error.
Comment 3 Ayushman Jain CLA 2011-06-09 07:07:52 EDT
Released in BETA_JAVA7 branch
Comment 4 Ayushman Jain CLA 2011-06-09 15:28:20 EDT
Created attachment 197725 [details]
minor update

Changed wording of error message according to Srikanth's suggestions. It now reads "Unhandled exception type {0}, caused by automatic closure of resource {1}"
Comment 5 Markus Keller CLA 2011-06-10 07:08:39 EDT
> "Unhandled exception type {0}, caused by automatic closure of resource {1}"

Does it really need to use the word "closure" that will likely be used for something different in Java 8?

We already have:
   Unhandled exception type {0} thrown by implicit super constructor

How about this?
   Unhandled exception type {0} thrown by automatic close() invocation on {1}
Comment 6 Srikanth Sankaran CLA 2011-06-10 07:40:56 EDT
(In reply to comment #5)

> How about this?
>    Unhandled exception type {0} thrown by automatic close() invocation on {1}

Sounds good to me.
Comment 7 Ayushman Jain CLA 2011-06-10 08:51:32 EDT
(In reply to comment #5)
> How about this?
>    Unhandled exception type {0} thrown by automatic close() invocation on {1}

Done.
Comment 8 Srikanth Sankaran CLA 2011-06-28 05:20:55 EDT
Verified using "Eclipse Java Development Tools Patch for Java 7 Support (BETA)	1.0.0.v20110623-0900	org.eclipse.jdt.patch.feature.group	Eclipse.org"