Proposal: Automatic Resource Management

Reinier Zwitserloot reinier at zwitserloot.com
Mon Mar 9 16:35:12 PDT 2009


A general note on the issue of InputStream.close():

It's a non-issue in my book. Yes - if you've read it all, received an  
EOF (or otherwise read all you've ever wanted from it), and then  
closing it fails, then it seems logical to just ignore that exception,  
but: That's *never* ever happened in my entire history of java usage.  
If an ARM block operating on an inputstream completes normally, and  
the close() operation throws an exception, then that exception would  
not be swallowed, which seems like an 'error', so to speak, but that  
happens (almost) never. Not worth hacking about by offering a way to  
choose between swallowing an exception on close or propagating it. If  
an API developer thinks it makes more sense to swallow exceptions on  
close, he should not be declaring them as thrown them in the first  
place. I'm sure any redesign of InputStream would strongly consider  
not letting its close() method throw IOException in the first place.

  --Reinier Zwitserloot
Like it? Tip it!
http://tipit.to



On Mar 10, 2009, at 00:17, Mark Mahieu wrote:

> Yuck.
>
> I guess one way to deal with this would be to track exceptions
> 'definitely thrown' by statements, and use different translations
> depending on whether there are any exceptions 'definitely' thrown by
> the body.  Not exactly a trivial addition to the spec though.
>
> Mark
>
>
> On 9 Mar 2009, at 20:06, Neal Gafter wrote:
>
>> On Mon, Mar 9, 2009 at 11:16 AM, Joshua Bloch <jjb at google.com> wrote:
>>> This URL should always point at the latest version:
>>> http://docs.google.com/Doc?id=ddv8ts74_0vnstdfdh
>>
>> The static exception analysis implied by the proposal's translation
>> doesn't match its dynamic semantics.  In the following program
>> snippet, the proposal requires an error message where shown, while  
>> the
>> dynamic semantics never allow the reported exception to occur.
>>
>>    static BufferedReader getReader(String name) {
>> 	// any implementation here
>>    }
>>    public static void main(String[] args) {
>> 	{
>> 	    try (BufferedReader localVar = getReader(args[0])) {
>> 	        throw new NullPointerException(args[0]);
>> 	    } // required language error: IOException not caught
>> 	}
>>    }
>>
>
>




More information about the coin-dev mailing list