review request for 7022624, convert java.io test to use try-with-resources
stuart.marks at oracle.com
Tue Mar 1 14:20:10 PST 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 java.io tests to use TWR.
>> * test/java/io/OutputStreamWriter/Encode.java
>> 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
> 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