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

Bug 348705

Summary: [1.7][compiler] Improve error message for unhandled IOException generated due to compiler-generated close()
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, markus.kell.r, satyam.kandula, srikanth_sankaran
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + regression tests
none
minor update none

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"