review request for 7022624, convert test to use try-with-resources

Stuart Marks stuart.marks at
Tue Mar 1 22:20:10 UTC 2011

On 3/1/11 1:46 AM, Alan Bateman wrote:
> Stuart Marks wrote:
>> Here's a small webrev with changes to a handful of tests to use TWR.


>> * test/java/io/OutputStreamWriter/
>> Pretty clearly a ServerSocket is a distinct resource from a Socket returned
>> from the accept() call. However, does Socket.getInputStream() represent a
>> distinct resource from the Socket? In this case it seemed most sensible to
>> unroll them into separate resource variables, but again I could go either way
>> on this.
> I wouldn't bother but would instead reduce this down to three resources, maybe:
> try (ServerSocket listener = ss;
>       Socket s = listener.accept();
>       BufferedReader reader = new BufferedReader(new
> InputStreamReader(s.getInputStream()))
> {
>     ...
> }

Sounds reasonable.

> While you are there, I assume ss should be final. Also might be good to put a
> try/finally around the encode at L50-52 to ensure that disconnect is called.

Yeah, both are a good idea.



More information about the core-libs-dev mailing list